29372933339975279ae88ff982535f48130a0ef1
[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   ;; For MONITORX and MWAITX support 
266   UNSPECV_MONITORX
267   UNSPECV_MWAITX
268
269 ])
270
271 ;; Constants to represent rounding modes in the ROUND instruction
272 (define_constants
273   [(ROUND_FLOOR                 0x1)
274    (ROUND_CEIL                  0x2)
275    (ROUND_TRUNC                 0x3)
276    (ROUND_MXCSR                 0x4)
277    (ROUND_NO_EXC                0x8)
278   ])
279
280 ;; Constants to represent AVX512F embeded rounding
281 (define_constants
282   [(ROUND_NEAREST_INT                   0)
283    (ROUND_NEG_INF                       1)
284    (ROUND_POS_INF                       2)
285    (ROUND_ZERO                          3)
286    (NO_ROUND                            4)
287    (ROUND_SAE                           8)
288   ])
289
290 ;; Constants to represent pcomtrue/pcomfalse variants
291 (define_constants
292   [(PCOM_FALSE                  0)
293    (PCOM_TRUE                   1)
294    (COM_FALSE_S                 2)
295    (COM_FALSE_P                 3)
296    (COM_TRUE_S                  4)
297    (COM_TRUE_P                  5)
298   ])
299
300 ;; Constants used in the XOP pperm instruction
301 (define_constants
302   [(PPERM_SRC                   0x00)   /* copy source */
303    (PPERM_INVERT                0x20)   /* invert source */
304    (PPERM_REVERSE               0x40)   /* bit reverse source */
305    (PPERM_REV_INV               0x60)   /* bit reverse & invert src */
306    (PPERM_ZERO                  0x80)   /* all 0's */
307    (PPERM_ONES                  0xa0)   /* all 1's */
308    (PPERM_SIGN                  0xc0)   /* propagate sign bit */
309    (PPERM_INV_SIGN              0xe0)   /* invert & propagate sign */
310    (PPERM_SRC1                  0x00)   /* use first source byte */
311    (PPERM_SRC2                  0x10)   /* use second source byte */
312    ])
313
314 ;; Registers by name.
315 (define_constants
316   [(AX_REG                       0)
317    (DX_REG                       1)
318    (CX_REG                       2)
319    (BX_REG                       3)
320    (SI_REG                       4)
321    (DI_REG                       5)
322    (BP_REG                       6)
323    (SP_REG                       7)
324    (ST0_REG                      8)
325    (ST1_REG                      9)
326    (ST2_REG                     10)
327    (ST3_REG                     11)
328    (ST4_REG                     12)
329    (ST5_REG                     13)
330    (ST6_REG                     14)
331    (ST7_REG                     15)
332    (FLAGS_REG                   17)
333    (FPSR_REG                    18)
334    (FPCR_REG                    19)
335    (XMM0_REG                    21)
336    (XMM1_REG                    22)
337    (XMM2_REG                    23)
338    (XMM3_REG                    24)
339    (XMM4_REG                    25)
340    (XMM5_REG                    26)
341    (XMM6_REG                    27)
342    (XMM7_REG                    28)
343    (MM0_REG                     29)
344    (MM1_REG                     30)
345    (MM2_REG                     31)
346    (MM3_REG                     32)
347    (MM4_REG                     33)
348    (MM5_REG                     34)
349    (MM6_REG                     35)
350    (MM7_REG                     36)
351    (R8_REG                      37)
352    (R9_REG                      38)
353    (R10_REG                     39)
354    (R11_REG                     40)
355    (R12_REG                     41)
356    (R13_REG                     42)
357    (R14_REG                     43)
358    (R15_REG                     44)
359    (XMM8_REG                    45)
360    (XMM9_REG                    46)
361    (XMM10_REG                   47)
362    (XMM11_REG                   48)
363    (XMM12_REG                   49)
364    (XMM13_REG                   50)
365    (XMM14_REG                   51)
366    (XMM15_REG                   52)
367    (XMM16_REG                   53)
368    (XMM17_REG                   54)
369    (XMM18_REG                   55)
370    (XMM19_REG                   56)
371    (XMM20_REG                   57)
372    (XMM21_REG                   58)
373    (XMM22_REG                   59)
374    (XMM23_REG                   60)
375    (XMM24_REG                   61)
376    (XMM25_REG                   62)
377    (XMM26_REG                   63)
378    (XMM27_REG                   64)
379    (XMM28_REG                   65)
380    (XMM29_REG                   66)
381    (XMM30_REG                   67)
382    (XMM31_REG                   68)
383    (MASK0_REG                   69)
384    (MASK1_REG                   70)
385    (MASK2_REG                   71)
386    (MASK3_REG                   72)
387    (MASK4_REG                   73)
388    (MASK5_REG                   74)
389    (MASK6_REG                   75)
390    (MASK7_REG                   76)
391    (BND0_REG                    77)
392    (BND1_REG                    78)
393   ])
394
395 ;; Insns whose names begin with "x86_" are emitted by gen_FOO calls
396 ;; from i386.c.
397
398 ;; In C guard expressions, put expressions which may be compile-time
399 ;; constants first.  This allows for better optimization.  For
400 ;; example, write "TARGET_64BIT && reload_completed", not
401 ;; "reload_completed && TARGET_64BIT".
402
403 \f
404 ;; Processor type.
405 (define_attr "cpu" "none,pentium,pentiumpro,geode,k6,athlon,k8,core2,nehalem,
406                     atom,slm,generic,amdfam10,bdver1,bdver2,bdver3,bdver4,
407                     btver2,knl"
408   (const (symbol_ref "ix86_schedule")))
409
410 ;; A basic instruction type.  Refinements due to arguments to be
411 ;; provided in other attributes.
412 (define_attr "type"
413   "other,multi,
414    alu,alu1,negnot,imov,imovx,lea,
415    incdec,ishift,ishiftx,ishift1,rotate,rotatex,rotate1,
416    imul,imulx,idiv,icmp,test,ibr,setcc,icmov,
417    push,pop,call,callv,leave,
418    str,bitmanip,
419    fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,
420    fxch,fistp,fisttp,frndint,
421    sse,ssemov,sseadd,sseadd1,sseiadd,sseiadd1,
422    ssemul,sseimul,ssediv,sselog,sselog1,
423    sseishft,sseishft1,ssecmp,ssecomi,
424    ssecvt,ssecvt1,sseicvt,sseins,
425    sseshuf,sseshuf1,ssemuladd,sse4arg,
426    lwp,mskmov,msklog,
427    mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft,
428    mpxmov,mpxmk,mpxchk,mpxld,mpxst"
429   (const_string "other"))
430
431 ;; Main data type used by the insn
432 (define_attr "mode"
433   "unknown,none,QI,HI,SI,DI,TI,OI,XI,SF,DF,XF,TF,V16SF,V8SF,V4DF,V4SF,
434   V2DF,V2SF,V1DF,V8DF"
435   (const_string "unknown"))
436
437 ;; The CPU unit operations uses.
438 (define_attr "unit" "integer,i387,sse,mmx,unknown"
439   (cond [(eq_attr "type" "fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,
440                           fxch,fistp,fisttp,frndint")
441            (const_string "i387")
442          (eq_attr "type" "sse,ssemov,sseadd,sseadd1,sseiadd,sseiadd1,
443                           ssemul,sseimul,ssediv,sselog,sselog1,
444                           sseishft,sseishft1,ssecmp,ssecomi,
445                           ssecvt,ssecvt1,sseicvt,sseins,
446                           sseshuf,sseshuf1,ssemuladd,sse4arg,mskmov")
447            (const_string "sse")
448          (eq_attr "type" "mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
449            (const_string "mmx")
450          (eq_attr "type" "other")
451            (const_string "unknown")]
452          (const_string "integer")))
453
454 ;; The minimum required alignment of vector mode memory operands of the SSE
455 ;; (non-VEX/EVEX) instruction in bits, if it is different from
456 ;; GET_MODE_ALIGNMENT of the operand, otherwise 0.  If an instruction has
457 ;; multiple alternatives, this should be conservative maximum of those minimum
458 ;; required alignments.
459 (define_attr "ssememalign" "" (const_int 0))
460
461 ;; The (bounding maximum) length of an instruction immediate.
462 (define_attr "length_immediate" ""
463   (cond [(eq_attr "type" "incdec,setcc,icmov,str,lea,other,multi,idiv,leave,
464                           bitmanip,imulx,msklog,mskmov,mpxmk,mpxmov,mpxchk,
465                           mpxld,mpxst")
466            (const_int 0)
467          (eq_attr "unit" "i387,sse,mmx")
468            (const_int 0)
469          (eq_attr "type" "alu,alu1,negnot,imovx,ishift,ishiftx,ishift1,
470                           rotate,rotatex,rotate1,imul,icmp,push,pop")
471            (symbol_ref "ix86_attr_length_immediate_default (insn, true)")
472          (eq_attr "type" "imov,test")
473            (symbol_ref "ix86_attr_length_immediate_default (insn, false)")
474          (eq_attr "type" "call")
475            (if_then_else (match_operand 0 "constant_call_address_operand")
476              (const_int 4)
477              (const_int 0))
478          (eq_attr "type" "callv")
479            (if_then_else (match_operand 1 "constant_call_address_operand")
480              (const_int 4)
481              (const_int 0))
482          ;; We don't know the size before shorten_branches.  Expect
483          ;; the instruction to fit for better scheduling.
484          (eq_attr "type" "ibr")
485            (const_int 1)
486          ]
487          (symbol_ref "/* Update immediate_length and other attributes! */
488                       gcc_unreachable (),1")))
489
490 ;; The (bounding maximum) length of an instruction address.
491 (define_attr "length_address" ""
492   (cond [(eq_attr "type" "str,other,multi,fxch")
493            (const_int 0)
494          (and (eq_attr "type" "call")
495               (match_operand 0 "constant_call_address_operand"))
496              (const_int 0)
497          (and (eq_attr "type" "callv")
498               (match_operand 1 "constant_call_address_operand"))
499              (const_int 0)
500          ]
501          (symbol_ref "ix86_attr_length_address_default (insn)")))
502
503 ;; Set when length prefix is used.
504 (define_attr "prefix_data16" ""
505   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
506            (const_int 0)
507          (eq_attr "mode" "HI")
508            (const_int 1)
509          (and (eq_attr "unit" "sse") (eq_attr "mode" "V2DF,TI"))
510            (const_int 1)
511         ]
512         (const_int 0)))
513
514 ;; Set when string REP prefix is used.
515 (define_attr "prefix_rep" ""
516   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
517            (const_int 0)
518          (and (eq_attr "unit" "sse") (eq_attr "mode" "SF,DF"))
519            (const_int 1)
520          (and (eq_attr "type" "ibr,call,callv")
521               (match_test "ix86_bnd_prefixed_insn_p (insn)"))
522            (const_int 1)
523         ]
524         (const_int 0)))
525
526 ;; Set when 0f opcode prefix is used.
527 (define_attr "prefix_0f" ""
528   (if_then_else
529     (ior (eq_attr "type" "imovx,setcc,icmov,bitmanip,msklog,mskmov,
530                           mpxmk,mpxmov,mpxchk,mpxld,mpxst")
531          (eq_attr "unit" "sse,mmx"))
532     (const_int 1)
533     (const_int 0)))
534
535 ;; Set when REX opcode prefix is used.
536 (define_attr "prefix_rex" ""
537   (cond [(not (match_test "TARGET_64BIT"))
538            (const_int 0)
539          (and (eq_attr "mode" "DI")
540               (and (eq_attr "type" "!push,pop,call,callv,leave,ibr")
541                    (eq_attr "unit" "!mmx")))
542            (const_int 1)
543          (and (eq_attr "mode" "QI")
544               (match_test "x86_extended_QIreg_mentioned_p (insn)"))
545            (const_int 1)
546          (match_test "x86_extended_reg_mentioned_p (insn)")
547            (const_int 1)
548          (and (eq_attr "type" "imovx")
549               (match_operand:QI 1 "ext_QIreg_operand"))
550            (const_int 1)
551         ]
552         (const_int 0)))
553
554 ;; There are also additional prefixes in 3DNOW, SSSE3.
555 ;; ssemuladd,sse4arg default to 0f24/0f25 and DREX byte,
556 ;; sseiadd1,ssecvt1 to 0f7a with no DREX byte.
557 ;; 3DNOW has 0f0f prefix, SSSE3 and SSE4_{1,2} 0f38/0f3a.
558 (define_attr "prefix_extra" ""
559   (cond [(eq_attr "type" "ssemuladd,sse4arg")
560            (const_int 2)
561          (eq_attr "type" "sseiadd1,ssecvt1")
562            (const_int 1)
563         ]
564         (const_int 0)))
565
566 ;; Prefix used: original, VEX or maybe VEX.
567 (define_attr "prefix" "orig,vex,maybe_vex,evex,maybe_evex"
568   (cond [(eq_attr "mode" "OI,V8SF,V4DF")
569            (const_string "vex")
570          (eq_attr "mode" "XI,V16SF,V8DF")
571            (const_string "evex")
572         ]
573         (const_string "orig")))
574
575 ;; VEX W bit is used.
576 (define_attr "prefix_vex_w" "" (const_int 0))
577
578 ;; The length of VEX prefix
579 ;; Only instructions with 0f prefix can have 2 byte VEX prefix,
580 ;; 0f38/0f3a prefixes can't.  In i386.md 0f3[8a] is
581 ;; still prefix_0f 1, with prefix_extra 1.
582 (define_attr "length_vex" ""
583   (if_then_else (and (eq_attr "prefix_0f" "1")
584                      (eq_attr "prefix_extra" "0"))
585     (if_then_else (eq_attr "prefix_vex_w" "1")
586       (symbol_ref "ix86_attr_length_vex_default (insn, true, true)")
587       (symbol_ref "ix86_attr_length_vex_default (insn, true, false)"))
588     (if_then_else (eq_attr "prefix_vex_w" "1")
589       (symbol_ref "ix86_attr_length_vex_default (insn, false, true)")
590       (symbol_ref "ix86_attr_length_vex_default (insn, false, false)"))))
591
592 ;; 4-bytes evex prefix and 1 byte opcode.
593 (define_attr "length_evex" "" (const_int 5))
594
595 ;; Set when modrm byte is used.
596 (define_attr "modrm" ""
597   (cond [(eq_attr "type" "str,leave")
598            (const_int 0)
599          (eq_attr "unit" "i387")
600            (const_int 0)
601          (and (eq_attr "type" "incdec")
602               (and (not (match_test "TARGET_64BIT"))
603                    (ior (match_operand:SI 1 "register_operand")
604                         (match_operand:HI 1 "register_operand"))))
605            (const_int 0)
606          (and (eq_attr "type" "push")
607               (not (match_operand 1 "memory_operand")))
608            (const_int 0)
609          (and (eq_attr "type" "pop")
610               (not (match_operand 0 "memory_operand")))
611            (const_int 0)
612          (and (eq_attr "type" "imov")
613               (and (not (eq_attr "mode" "DI"))
614                    (ior (and (match_operand 0 "register_operand")
615                              (match_operand 1 "immediate_operand"))
616                         (ior (and (match_operand 0 "ax_reg_operand")
617                                   (match_operand 1 "memory_displacement_only_operand"))
618                              (and (match_operand 0 "memory_displacement_only_operand")
619                                   (match_operand 1 "ax_reg_operand"))))))
620            (const_int 0)
621          (and (eq_attr "type" "call")
622               (match_operand 0 "constant_call_address_operand"))
623              (const_int 0)
624          (and (eq_attr "type" "callv")
625               (match_operand 1 "constant_call_address_operand"))
626              (const_int 0)
627          (and (eq_attr "type" "alu,alu1,icmp,test")
628               (match_operand 0 "ax_reg_operand"))
629              (symbol_ref "(get_attr_length_immediate (insn) <= (get_attr_mode (insn) != MODE_QI))")
630          ]
631          (const_int 1)))
632
633 ;; When this attribute is set, calculate total insn length from
634 ;; length_nobnd attribute, prefixed with eventual bnd prefix byte
635 (define_attr "length_nobnd" "" (const_int 0))
636
637 ;; The (bounding maximum) length of an instruction in bytes.
638 ;; ??? fistp and frndint are in fact fldcw/{fistp,frndint}/fldcw sequences.
639 ;; Later we may want to split them and compute proper length as for
640 ;; other insns.
641 (define_attr "length" ""
642   (cond [(eq_attr "length_nobnd" "!0")
643            (plus (symbol_ref ("ix86_bnd_prefixed_insn_p (insn)"))
644                  (attr "length_nobnd"))
645          (eq_attr "type" "other,multi,fistp,frndint")
646            (const_int 16)
647          (eq_attr "type" "fcmp")
648            (const_int 4)
649          (eq_attr "unit" "i387")
650            (plus (const_int 2)
651                  (plus (attr "prefix_data16")
652                        (attr "length_address")))
653          (ior (eq_attr "prefix" "evex")
654               (and (ior (eq_attr "prefix" "maybe_evex")
655                         (eq_attr "prefix" "maybe_vex"))
656                    (match_test "TARGET_AVX512F")))
657            (plus (attr "length_evex")
658                  (plus (attr "length_immediate")
659                        (plus (attr "modrm")
660                              (attr "length_address"))))
661          (ior (eq_attr "prefix" "vex")
662               (and (ior (eq_attr "prefix" "maybe_vex")
663                         (eq_attr "prefix" "maybe_evex"))
664                    (match_test "TARGET_AVX")))
665            (plus (attr "length_vex")
666                  (plus (attr "length_immediate")
667                        (plus (attr "modrm")
668                              (attr "length_address"))))]
669          (plus (plus (attr "modrm")
670                      (plus (attr "prefix_0f")
671                            (plus (attr "prefix_rex")
672                                  (plus (attr "prefix_extra")
673                                        (const_int 1)))))
674                (plus (attr "prefix_rep")
675                      (plus (attr "prefix_data16")
676                            (plus (attr "length_immediate")
677                                  (attr "length_address")))))))
678
679 ;; The `memory' attribute is `none' if no memory is referenced, `load' or
680 ;; `store' if there is a simple memory reference therein, or `unknown'
681 ;; if the instruction is complex.
682
683 (define_attr "memory" "none,load,store,both,unknown"
684   (cond [(eq_attr "type" "other,multi,str,lwp")
685            (const_string "unknown")
686          (eq_attr "type" "lea,fcmov,fpspc,mpxmk,mpxchk")
687            (const_string "none")
688          (eq_attr "type" "fistp,leave")
689            (const_string "both")
690          (eq_attr "type" "frndint")
691            (const_string "load")
692          (eq_attr "type" "mpxld")
693            (const_string "load")
694          (eq_attr "type" "mpxst")
695            (const_string "store")
696          (eq_attr "type" "push")
697            (if_then_else (match_operand 1 "memory_operand")
698              (const_string "both")
699              (const_string "store"))
700          (eq_attr "type" "pop")
701            (if_then_else (match_operand 0 "memory_operand")
702              (const_string "both")
703              (const_string "load"))
704          (eq_attr "type" "setcc")
705            (if_then_else (match_operand 0 "memory_operand")
706              (const_string "store")
707              (const_string "none"))
708          (eq_attr "type" "icmp,test,ssecmp,ssecomi,mmxcmp,fcmp")
709            (if_then_else (ior (match_operand 0 "memory_operand")
710                               (match_operand 1 "memory_operand"))
711              (const_string "load")
712              (const_string "none"))
713          (eq_attr "type" "ibr")
714            (if_then_else (match_operand 0 "memory_operand")
715              (const_string "load")
716              (const_string "none"))
717          (eq_attr "type" "call")
718            (if_then_else (match_operand 0 "constant_call_address_operand")
719              (const_string "none")
720              (const_string "load"))
721          (eq_attr "type" "callv")
722            (if_then_else (match_operand 1 "constant_call_address_operand")
723              (const_string "none")
724              (const_string "load"))
725          (and (eq_attr "type" "alu1,negnot,ishift1,sselog1,sseshuf1")
726               (match_operand 1 "memory_operand"))
727            (const_string "both")
728          (and (match_operand 0 "memory_operand")
729               (match_operand 1 "memory_operand"))
730            (const_string "both")
731          (match_operand 0 "memory_operand")
732            (const_string "store")
733          (match_operand 1 "memory_operand")
734            (const_string "load")
735          (and (eq_attr "type"
736                  "!alu1,negnot,ishift1,
737                    imov,imovx,icmp,test,bitmanip,
738                    fmov,fcmp,fsgn,
739                    sse,ssemov,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,
740                    sselog1,sseshuf1,sseadd1,sseiadd1,sseishft1,
741                    mmx,mmxmov,mmxcmp,mmxcvt,mskmov,msklog,mpxmov")
742               (match_operand 2 "memory_operand"))
743            (const_string "load")
744          (and (eq_attr "type" "icmov,ssemuladd,sse4arg")
745               (match_operand 3 "memory_operand"))
746            (const_string "load")
747         ]
748         (const_string "none")))
749
750 ;; Indicates if an instruction has both an immediate and a displacement.
751
752 (define_attr "imm_disp" "false,true,unknown"
753   (cond [(eq_attr "type" "other,multi")
754            (const_string "unknown")
755          (and (eq_attr "type" "icmp,test,imov,alu1,ishift1,rotate1")
756               (and (match_operand 0 "memory_displacement_operand")
757                    (match_operand 1 "immediate_operand")))
758            (const_string "true")
759          (and (eq_attr "type" "alu,ishift,ishiftx,rotate,rotatex,imul,idiv")
760               (and (match_operand 0 "memory_displacement_operand")
761                    (match_operand 2 "immediate_operand")))
762            (const_string "true")
763         ]
764         (const_string "false")))
765
766 ;; Indicates if an FP operation has an integer source.
767
768 (define_attr "fp_int_src" "false,true"
769   (const_string "false"))
770
771 ;; Defines rounding mode of an FP operation.
772
773 (define_attr "i387_cw" "trunc,floor,ceil,mask_pm,uninitialized,any"
774   (const_string "any"))
775
776 ;; Define attribute to classify add/sub insns that consumes carry flag (CF)
777 (define_attr "use_carry" "0,1" (const_string "0"))
778
779 ;; Define attribute to indicate unaligned ssemov insns
780 (define_attr "movu" "0,1" (const_string "0"))
781
782 ;; Used to control the "enabled" attribute on a per-instruction basis.
783 (define_attr "isa" "base,x64,x64_sse4,x64_sse4_noavx,x64_avx,nox64,
784                     sse2,sse2_noavx,sse3,sse4,sse4_noavx,avx,noavx,
785                     avx2,noavx2,bmi,bmi2,fma4,fma,avx512f,noavx512f,
786                     fma_avx512f,avx512bw,noavx512bw,avx512dq,noavx512dq"
787   (const_string "base"))
788
789 (define_attr "enabled" ""
790   (cond [(eq_attr "isa" "x64") (symbol_ref "TARGET_64BIT")
791          (eq_attr "isa" "x64_sse4")
792            (symbol_ref "TARGET_64BIT && TARGET_SSE4_1")
793          (eq_attr "isa" "x64_sse4_noavx")
794            (symbol_ref "TARGET_64BIT && TARGET_SSE4_1 && !TARGET_AVX")
795          (eq_attr "isa" "x64_avx")
796            (symbol_ref "TARGET_64BIT && TARGET_AVX")
797          (eq_attr "isa" "nox64") (symbol_ref "!TARGET_64BIT")
798          (eq_attr "isa" "sse2") (symbol_ref "TARGET_SSE2")
799          (eq_attr "isa" "sse2_noavx")
800            (symbol_ref "TARGET_SSE2 && !TARGET_AVX")
801          (eq_attr "isa" "sse3") (symbol_ref "TARGET_SSE3")
802          (eq_attr "isa" "sse4") (symbol_ref "TARGET_SSE4_1")
803          (eq_attr "isa" "sse4_noavx")
804            (symbol_ref "TARGET_SSE4_1 && !TARGET_AVX")
805          (eq_attr "isa" "avx") (symbol_ref "TARGET_AVX")
806          (eq_attr "isa" "noavx") (symbol_ref "!TARGET_AVX")
807          (eq_attr "isa" "avx2") (symbol_ref "TARGET_AVX2")
808          (eq_attr "isa" "noavx2") (symbol_ref "!TARGET_AVX2")
809          (eq_attr "isa" "bmi") (symbol_ref "TARGET_BMI")
810          (eq_attr "isa" "bmi2") (symbol_ref "TARGET_BMI2")
811          (eq_attr "isa" "fma4") (symbol_ref "TARGET_FMA4")
812          (eq_attr "isa" "fma") (symbol_ref "TARGET_FMA")
813          (eq_attr "isa" "avx512f") (symbol_ref "TARGET_AVX512F")
814          (eq_attr "isa" "noavx512f") (symbol_ref "!TARGET_AVX512F")
815          (eq_attr "isa" "fma_avx512f")
816            (symbol_ref "TARGET_FMA || TARGET_AVX512F")
817          (eq_attr "isa" "avx512bw") (symbol_ref "TARGET_AVX512BW")
818          (eq_attr "isa" "noavx512bw") (symbol_ref "!TARGET_AVX512BW")
819          (eq_attr "isa" "avx512dq") (symbol_ref "TARGET_AVX512DQ")
820          (eq_attr "isa" "noavx512dq") (symbol_ref "!TARGET_AVX512DQ")
821         ]
822         (const_int 1)))
823
824 (define_attr "preferred_for_size" "" (const_int 1))
825 (define_attr "preferred_for_speed" "" (const_int 1))
826
827 ;; Describe a user's asm statement.
828 (define_asm_attributes
829   [(set_attr "length" "128")
830    (set_attr "type" "multi")])
831
832 (define_code_iterator plusminus [plus minus])
833
834 (define_code_iterator sat_plusminus [ss_plus us_plus ss_minus us_minus])
835
836 (define_code_iterator multdiv [mult div])
837
838 ;; Base name for define_insn
839 (define_code_attr plusminus_insn
840   [(plus "add") (ss_plus "ssadd") (us_plus "usadd")
841    (minus "sub") (ss_minus "sssub") (us_minus "ussub")])
842
843 ;; Base name for insn mnemonic.
844 (define_code_attr plusminus_mnemonic
845   [(plus "add") (ss_plus "adds") (us_plus "addus")
846    (minus "sub") (ss_minus "subs") (us_minus "subus")])
847 (define_code_attr plusminus_carry_mnemonic
848   [(plus "adc") (minus "sbb")])
849 (define_code_attr multdiv_mnemonic
850   [(mult "mul") (div "div")])
851
852 ;; Mark commutative operators as such in constraints.
853 (define_code_attr comm [(plus "%") (ss_plus "%") (us_plus "%")
854                         (minus "") (ss_minus "") (us_minus "")])
855
856 ;; Mapping of max and min
857 (define_code_iterator maxmin [smax smin umax umin])
858
859 ;; Mapping of signed max and min
860 (define_code_iterator smaxmin [smax smin])
861
862 ;; Mapping of unsigned max and min
863 (define_code_iterator umaxmin [umax umin])
864
865 ;; Base name for integer and FP insn mnemonic
866 (define_code_attr maxmin_int [(smax "maxs") (smin "mins")
867                               (umax "maxu") (umin "minu")])
868 (define_code_attr maxmin_float [(smax "max") (smin "min")])
869
870 ;; Mapping of logic operators
871 (define_code_iterator any_logic [and ior xor])
872 (define_code_iterator any_or [ior xor])
873 (define_code_iterator fpint_logic [and xor])
874
875 ;; Base name for insn mnemonic.
876 (define_code_attr logic [(and "and") (ior "or") (xor "xor")])
877
878 ;; Mapping of logic-shift operators
879 (define_code_iterator any_lshift [ashift lshiftrt])
880
881 ;; Mapping of shift-right operators
882 (define_code_iterator any_shiftrt [lshiftrt ashiftrt])
883
884 ;; Mapping of all shift operators
885 (define_code_iterator any_shift [ashift lshiftrt ashiftrt])
886
887 ;; Base name for define_insn
888 (define_code_attr shift_insn
889   [(ashift "ashl") (lshiftrt "lshr") (ashiftrt "ashr")])
890
891 ;; Base name for insn mnemonic.
892 (define_code_attr shift [(ashift "sll") (lshiftrt "shr") (ashiftrt "sar")])
893 (define_code_attr vshift [(ashift "sll") (lshiftrt "srl") (ashiftrt "sra")])
894
895 ;; Mapping of rotate operators
896 (define_code_iterator any_rotate [rotate rotatert])
897
898 ;; Base name for define_insn
899 (define_code_attr rotate_insn [(rotate "rotl") (rotatert "rotr")])
900
901 ;; Base name for insn mnemonic.
902 (define_code_attr rotate [(rotate "rol") (rotatert "ror")])
903
904 ;; Mapping of abs neg operators
905 (define_code_iterator absneg [abs neg])
906
907 ;; Base name for x87 insn mnemonic.
908 (define_code_attr absneg_mnemonic [(abs "abs") (neg "chs")])
909
910 ;; Used in signed and unsigned widening multiplications.
911 (define_code_iterator any_extend [sign_extend zero_extend])
912
913 ;; Prefix for insn menmonic.
914 (define_code_attr sgnprefix [(sign_extend "i") (zero_extend "")])
915
916 ;; Prefix for define_insn
917 (define_code_attr u [(sign_extend "") (zero_extend "u")])
918 (define_code_attr s [(sign_extend "s") (zero_extend "u")])
919 (define_code_attr u_bool [(sign_extend "false") (zero_extend "true")])
920
921 ;; Used in signed and unsigned truncations.
922 (define_code_iterator any_truncate [ss_truncate truncate us_truncate])
923 ;; Instruction suffix for truncations.
924 (define_code_attr trunsuffix [(ss_truncate "s") (truncate "") (us_truncate "us")])
925
926 ;; Used in signed and unsigned fix.
927 (define_code_iterator any_fix [fix unsigned_fix])
928 (define_code_attr fixsuffix [(fix "") (unsigned_fix "u")])
929
930 ;; Used in signed and unsigned float.
931 (define_code_iterator any_float [float unsigned_float])
932 (define_code_attr floatsuffix [(float "") (unsigned_float "u")])
933
934 ;; All integer modes.
935 (define_mode_iterator SWI1248x [QI HI SI DI])
936
937 ;; All integer modes with AVX512BW.
938 (define_mode_iterator SWI1248_AVX512BW
939   [QI HI (SI "TARGET_AVX512BW") (DI "TARGET_AVX512BW")])
940
941 ;; All integer modes without QImode.
942 (define_mode_iterator SWI248x [HI SI DI])
943
944 ;; All integer modes without QImode and HImode.
945 (define_mode_iterator SWI48x [SI DI])
946
947 ;; All integer modes without SImode and DImode.
948 (define_mode_iterator SWI12 [QI HI])
949
950 ;; All integer modes without DImode.
951 (define_mode_iterator SWI124 [QI HI SI])
952
953 ;; All integer modes without QImode and DImode.
954 (define_mode_iterator SWI24 [HI SI])
955
956 ;; Single word integer modes.
957 (define_mode_iterator SWI [QI HI SI (DI "TARGET_64BIT")])
958
959 ;; Single word integer modes without QImode.
960 (define_mode_iterator SWI248 [HI SI (DI "TARGET_64BIT")])
961
962 ;; Single word integer modes without QImode and HImode.
963 (define_mode_iterator SWI48 [SI (DI "TARGET_64BIT")])
964
965 ;; All math-dependant single and double word integer modes.
966 (define_mode_iterator SDWIM [(QI "TARGET_QIMODE_MATH")
967                              (HI "TARGET_HIMODE_MATH")
968                              SI DI (TI "TARGET_64BIT")])
969
970 ;; Math-dependant single word integer modes.
971 (define_mode_iterator SWIM [(QI "TARGET_QIMODE_MATH")
972                             (HI "TARGET_HIMODE_MATH")
973                             SI (DI "TARGET_64BIT")])
974
975 ;; Math-dependant integer modes without DImode.
976 (define_mode_iterator SWIM124 [(QI "TARGET_QIMODE_MATH")
977                                (HI "TARGET_HIMODE_MATH")
978                                SI])
979
980 ;; Math-dependant single word integer modes without QImode.
981 (define_mode_iterator SWIM248 [(HI "TARGET_HIMODE_MATH")
982                                SI (DI "TARGET_64BIT")])
983
984 ;; Double word integer modes.
985 (define_mode_iterator DWI [(DI "!TARGET_64BIT")
986                            (TI "TARGET_64BIT")])
987
988 ;; GET_MODE_SIZE for selected modes.  As GET_MODE_SIZE is not
989 ;; compile time constant, it is faster to use <MODE_SIZE> than
990 ;; GET_MODE_SIZE (<MODE>mode).  For XFmode which depends on
991 ;; command line options just use GET_MODE_SIZE macro.
992 (define_mode_attr MODE_SIZE [(QI "1") (HI "2") (SI "4") (DI "8") (TI "16")
993                              (SF "4") (DF "8") (XF "GET_MODE_SIZE (XFmode)")
994                              (V16QI "16") (V32QI "32") (V64QI "64")
995                              (V8HI "16") (V16HI "32") (V32HI "64")
996                              (V4SI "16") (V8SI "32") (V16SI "64")
997                              (V2DI "16") (V4DI "32") (V8DI "64")
998                              (V1TI "16") (V2TI "32") (V4TI "64")
999                              (V2DF "16") (V4DF "32") (V8DF "64")
1000                              (V4SF "16") (V8SF "32") (V16SF "64")])
1001
1002 ;; Double word integer modes as mode attribute.
1003 (define_mode_attr DWI [(QI "HI") (HI "SI") (SI "DI") (DI "TI")])
1004 (define_mode_attr dwi [(QI "hi") (HI "si") (SI "di") (DI "ti")])
1005
1006 ;; Half mode for double word integer modes.
1007 (define_mode_iterator DWIH [(SI "!TARGET_64BIT")
1008                             (DI "TARGET_64BIT")])
1009
1010 ;; Bound modes.
1011 (define_mode_iterator BND [(BND32 "!TARGET_LP64")
1012                            (BND64 "TARGET_LP64")])
1013
1014 ;; Pointer mode corresponding to bound mode.
1015 (define_mode_attr bnd_ptr [(BND32 "SI") (BND64 "DI")])
1016
1017 ;; MPX check types
1018 (define_int_iterator BNDCHECK [UNSPEC_BNDCL UNSPEC_BNDCU UNSPEC_BNDCN])
1019
1020 ;; Check name
1021 (define_int_attr bndcheck [(UNSPEC_BNDCL "cl")
1022                            (UNSPEC_BNDCU "cu")
1023                            (UNSPEC_BNDCN "cn")])
1024
1025 ;; Instruction suffix for integer modes.
1026 (define_mode_attr imodesuffix [(QI "b") (HI "w") (SI "l") (DI "q")])
1027
1028 ;; Instruction suffix for masks.
1029 (define_mode_attr mskmodesuffix [(QI "b") (HI "w") (SI "d") (DI "q")])
1030
1031 ;; Pointer size prefix for integer modes (Intel asm dialect)
1032 (define_mode_attr iptrsize [(QI "BYTE")
1033                             (HI "WORD")
1034                             (SI "DWORD")
1035                             (DI "QWORD")])
1036
1037 ;; Register class for integer modes.
1038 (define_mode_attr r [(QI "q") (HI "r") (SI "r") (DI "r")])
1039
1040 ;; Immediate operand constraint for integer modes.
1041 (define_mode_attr i [(QI "n") (HI "n") (SI "e") (DI "e")])
1042
1043 ;; General operand constraint for word modes.
1044 (define_mode_attr g [(QI "qmn") (HI "rmn") (SI "rme") (DI "rme")])
1045
1046 ;; Immediate operand constraint for double integer modes.
1047 (define_mode_attr di [(SI "nF") (DI "e")])
1048
1049 ;; Immediate operand constraint for shifts.
1050 (define_mode_attr S [(QI "I") (HI "I") (SI "I") (DI "J") (TI "O")])
1051
1052 ;; General operand predicate for integer modes.
1053 (define_mode_attr general_operand
1054         [(QI "general_operand")
1055          (HI "general_operand")
1056          (SI "x86_64_general_operand")
1057          (DI "x86_64_general_operand")
1058          (TI "x86_64_general_operand")])
1059
1060 ;; General sign extend operand predicate for integer modes,
1061 ;; which disallows VOIDmode operands and thus it is suitable
1062 ;; for use inside sign_extend.
1063 (define_mode_attr general_sext_operand
1064         [(QI "sext_operand")
1065          (HI "sext_operand")
1066          (SI "x86_64_sext_operand")
1067          (DI "x86_64_sext_operand")])
1068
1069 ;; General sign/zero extend operand predicate for integer modes.
1070 (define_mode_attr general_szext_operand
1071         [(QI "general_operand")
1072          (HI "general_operand")
1073          (SI "x86_64_szext_general_operand")
1074          (DI "x86_64_szext_general_operand")])
1075
1076 ;; Immediate operand predicate for integer modes.
1077 (define_mode_attr immediate_operand
1078         [(QI "immediate_operand")
1079          (HI "immediate_operand")
1080          (SI "x86_64_immediate_operand")
1081          (DI "x86_64_immediate_operand")])
1082
1083 ;; Nonmemory operand predicate for integer modes.
1084 (define_mode_attr nonmemory_operand
1085         [(QI "nonmemory_operand")
1086          (HI "nonmemory_operand")
1087          (SI "x86_64_nonmemory_operand")
1088          (DI "x86_64_nonmemory_operand")])
1089
1090 ;; Operand predicate for shifts.
1091 (define_mode_attr shift_operand
1092         [(QI "nonimmediate_operand")
1093          (HI "nonimmediate_operand")
1094          (SI "nonimmediate_operand")
1095          (DI "shiftdi_operand")
1096          (TI "register_operand")])
1097
1098 ;; Operand predicate for shift argument.
1099 (define_mode_attr shift_immediate_operand
1100         [(QI "const_1_to_31_operand")
1101          (HI "const_1_to_31_operand")
1102          (SI "const_1_to_31_operand")
1103          (DI "const_1_to_63_operand")])
1104
1105 ;; Input operand predicate for arithmetic left shifts.
1106 (define_mode_attr ashl_input_operand
1107         [(QI "nonimmediate_operand")
1108          (HI "nonimmediate_operand")
1109          (SI "nonimmediate_operand")
1110          (DI "ashldi_input_operand")
1111          (TI "reg_or_pm1_operand")])
1112
1113 ;; SSE and x87 SFmode and DFmode floating point modes
1114 (define_mode_iterator MODEF [SF DF])
1115
1116 ;; All x87 floating point modes
1117 (define_mode_iterator X87MODEF [SF DF XF])
1118
1119 ;; SSE instruction suffix for various modes
1120 (define_mode_attr ssemodesuffix
1121   [(SF "ss") (DF "sd")
1122    (V16SF "ps") (V8DF "pd")
1123    (V8SF "ps") (V4DF "pd")
1124    (V4SF "ps") (V2DF "pd")
1125    (V16QI "b") (V8HI "w") (V4SI "d") (V2DI "q")
1126    (V32QI "b") (V16HI "w") (V8SI "d") (V4DI "q")
1127    (V64QI "b") (V32HI "w") (V16SI "d") (V8DI "q")])
1128
1129 ;; SSE vector suffix for floating point modes
1130 (define_mode_attr ssevecmodesuffix [(SF "ps") (DF "pd")])
1131
1132 ;; SSE vector mode corresponding to a scalar mode
1133 (define_mode_attr ssevecmode
1134   [(QI "V16QI") (HI "V8HI") (SI "V4SI") (DI "V2DI") (SF "V4SF") (DF "V2DF")])
1135 (define_mode_attr ssevecmodelower
1136   [(QI "v16qi") (HI "v8hi") (SI "v4si") (DI "v2di") (SF "v4sf") (DF "v2df")])
1137
1138 ;; Instruction suffix for REX 64bit operators.
1139 (define_mode_attr rex64suffix [(SI "") (DI "{q}")])
1140
1141 ;; This mode iterator allows :P to be used for patterns that operate on
1142 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
1143 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
1144
1145 ;; This mode iterator allows :W to be used for patterns that operate on
1146 ;; word_mode sized quantities.
1147 (define_mode_iterator W
1148   [(SI "word_mode == SImode") (DI "word_mode == DImode")])
1149
1150 ;; This mode iterator allows :PTR to be used for patterns that operate on
1151 ;; ptr_mode sized quantities.
1152 (define_mode_iterator PTR
1153   [(SI "ptr_mode == SImode") (DI "ptr_mode == DImode")])
1154 \f
1155 ;; Scheduling descriptions
1156
1157 (include "pentium.md")
1158 (include "ppro.md")
1159 (include "k6.md")
1160 (include "athlon.md")
1161 (include "bdver1.md")
1162 (include "bdver3.md")
1163 (include "btver2.md")
1164 (include "geode.md")
1165 (include "atom.md")
1166 (include "slm.md")
1167 (include "core2.md")
1168
1169 \f
1170 ;; Operand and operator predicates and constraints
1171
1172 (include "predicates.md")
1173 (include "constraints.md")
1174
1175 \f
1176 ;; Compare and branch/compare and store instructions.
1177
1178 (define_expand "cbranch<mode>4"
1179   [(set (reg:CC FLAGS_REG)
1180         (compare:CC (match_operand:SDWIM 1 "nonimmediate_operand")
1181                     (match_operand:SDWIM 2 "<general_operand>")))
1182    (set (pc) (if_then_else
1183                (match_operator 0 "ordered_comparison_operator"
1184                 [(reg:CC FLAGS_REG) (const_int 0)])
1185                (label_ref (match_operand 3))
1186                (pc)))]
1187   ""
1188 {
1189   if (MEM_P (operands[1]) && MEM_P (operands[2]))
1190     operands[1] = force_reg (<MODE>mode, operands[1]);
1191   ix86_expand_branch (GET_CODE (operands[0]),
1192                       operands[1], operands[2], operands[3]);
1193   DONE;
1194 })
1195
1196 (define_expand "cstore<mode>4"
1197   [(set (reg:CC FLAGS_REG)
1198         (compare:CC (match_operand:SWIM 2 "nonimmediate_operand")
1199                     (match_operand:SWIM 3 "<general_operand>")))
1200    (set (match_operand:QI 0 "register_operand")
1201         (match_operator 1 "ordered_comparison_operator"
1202           [(reg:CC FLAGS_REG) (const_int 0)]))]
1203   ""
1204 {
1205   if (MEM_P (operands[2]) && MEM_P (operands[3]))
1206     operands[2] = force_reg (<MODE>mode, operands[2]);
1207   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1208                      operands[2], operands[3]);
1209   DONE;
1210 })
1211
1212 (define_expand "cmp<mode>_1"
1213   [(set (reg:CC FLAGS_REG)
1214         (compare:CC (match_operand:SWI48 0 "nonimmediate_operand")
1215                     (match_operand:SWI48 1 "<general_operand>")))])
1216
1217 (define_insn "*cmp<mode>_ccno_1"
1218   [(set (reg FLAGS_REG)
1219         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>,?m<r>")
1220                  (match_operand:SWI 1 "const0_operand")))]
1221   "ix86_match_ccmode (insn, CCNOmode)"
1222   "@
1223    test{<imodesuffix>}\t%0, %0
1224    cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1225   [(set_attr "type" "test,icmp")
1226    (set_attr "length_immediate" "0,1")
1227    (set_attr "mode" "<MODE>")])
1228
1229 (define_insn "*cmp<mode>_1"
1230   [(set (reg FLAGS_REG)
1231         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1232                  (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m")))]
1233   "ix86_match_ccmode (insn, CCmode)"
1234   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1235   [(set_attr "type" "icmp")
1236    (set_attr "mode" "<MODE>")])
1237
1238 (define_insn "*cmp<mode>_minus_1"
1239   [(set (reg FLAGS_REG)
1240         (compare
1241           (minus:SWI (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1242                      (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m"))
1243           (const_int 0)))]
1244   "ix86_match_ccmode (insn, CCGOCmode)"
1245   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1246   [(set_attr "type" "icmp")
1247    (set_attr "mode" "<MODE>")])
1248
1249 (define_insn "*cmpqi_ext_1"
1250   [(set (reg FLAGS_REG)
1251         (compare
1252           (match_operand:QI 0 "nonimmediate_x64nomem_operand" "Q,m")
1253           (subreg:QI
1254             (zero_extract:SI
1255               (match_operand 1 "ext_register_operand" "Q,Q")
1256               (const_int 8)
1257               (const_int 8)) 0)))]
1258   "ix86_match_ccmode (insn, CCmode)"
1259   "cmp{b}\t{%h1, %0|%0, %h1}"
1260   [(set_attr "isa" "*,nox64")
1261    (set_attr "type" "icmp")
1262    (set_attr "mode" "QI")])
1263
1264 (define_insn "*cmpqi_ext_2"
1265   [(set (reg FLAGS_REG)
1266         (compare
1267           (subreg:QI
1268             (zero_extract:SI
1269               (match_operand 0 "ext_register_operand" "Q")
1270               (const_int 8)
1271               (const_int 8)) 0)
1272           (match_operand:QI 1 "const0_operand")))]
1273   "ix86_match_ccmode (insn, CCNOmode)"
1274   "test{b}\t%h0, %h0"
1275   [(set_attr "type" "test")
1276    (set_attr "length_immediate" "0")
1277    (set_attr "mode" "QI")])
1278
1279 (define_expand "cmpqi_ext_3"
1280   [(set (reg:CC FLAGS_REG)
1281         (compare:CC
1282           (subreg:QI
1283             (zero_extract:SI
1284               (match_operand 0 "ext_register_operand")
1285               (const_int 8)
1286               (const_int 8)) 0)
1287           (match_operand:QI 1 "const_int_operand")))])
1288
1289 (define_insn "*cmpqi_ext_3"
1290   [(set (reg FLAGS_REG)
1291         (compare
1292           (subreg:QI
1293             (zero_extract:SI
1294               (match_operand 0 "ext_register_operand" "Q,Q")
1295               (const_int 8)
1296               (const_int 8)) 0)
1297           (match_operand:QI 1 "general_x64nomem_operand" "Qn,m")))]
1298   "ix86_match_ccmode (insn, CCmode)"
1299   "cmp{b}\t{%1, %h0|%h0, %1}"
1300   [(set_attr "isa" "*,nox64")
1301    (set_attr "type" "icmp")
1302    (set_attr "modrm" "1")
1303    (set_attr "mode" "QI")])
1304
1305 (define_insn "*cmpqi_ext_4"
1306   [(set (reg FLAGS_REG)
1307         (compare
1308           (subreg:QI
1309             (zero_extract:SI
1310               (match_operand 0 "ext_register_operand" "Q")
1311               (const_int 8)
1312               (const_int 8)) 0)
1313           (subreg:QI
1314             (zero_extract:SI
1315               (match_operand 1 "ext_register_operand" "Q")
1316               (const_int 8)
1317               (const_int 8)) 0)))]
1318   "ix86_match_ccmode (insn, CCmode)"
1319   "cmp{b}\t{%h1, %h0|%h0, %h1}"
1320   [(set_attr "type" "icmp")
1321    (set_attr "mode" "QI")])
1322
1323 ;; These implement float point compares.
1324 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
1325 ;; which would allow mix and match FP modes on the compares.  Which is what
1326 ;; the old patterns did, but with many more of them.
1327
1328 (define_expand "cbranchxf4"
1329   [(set (reg:CC FLAGS_REG)
1330         (compare:CC (match_operand:XF 1 "nonmemory_operand")
1331                     (match_operand:XF 2 "nonmemory_operand")))
1332    (set (pc) (if_then_else
1333               (match_operator 0 "ix86_fp_comparison_operator"
1334                [(reg:CC FLAGS_REG)
1335                 (const_int 0)])
1336               (label_ref (match_operand 3))
1337               (pc)))]
1338   "TARGET_80387"
1339 {
1340   ix86_expand_branch (GET_CODE (operands[0]),
1341                       operands[1], operands[2], operands[3]);
1342   DONE;
1343 })
1344
1345 (define_expand "cstorexf4"
1346   [(set (reg:CC FLAGS_REG)
1347         (compare:CC (match_operand:XF 2 "nonmemory_operand")
1348                     (match_operand:XF 3 "nonmemory_operand")))
1349    (set (match_operand:QI 0 "register_operand")
1350               (match_operator 1 "ix86_fp_comparison_operator"
1351                [(reg:CC FLAGS_REG)
1352                 (const_int 0)]))]
1353   "TARGET_80387"
1354 {
1355   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1356                      operands[2], operands[3]);
1357   DONE;
1358 })
1359
1360 (define_expand "cbranch<mode>4"
1361   [(set (reg:CC FLAGS_REG)
1362         (compare:CC (match_operand:MODEF 1 "cmp_fp_expander_operand")
1363                     (match_operand:MODEF 2 "cmp_fp_expander_operand")))
1364    (set (pc) (if_then_else
1365               (match_operator 0 "ix86_fp_comparison_operator"
1366                [(reg:CC FLAGS_REG)
1367                 (const_int 0)])
1368               (label_ref (match_operand 3))
1369               (pc)))]
1370   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1371 {
1372   ix86_expand_branch (GET_CODE (operands[0]),
1373                       operands[1], operands[2], operands[3]);
1374   DONE;
1375 })
1376
1377 (define_expand "cstore<mode>4"
1378   [(set (reg:CC FLAGS_REG)
1379         (compare:CC (match_operand:MODEF 2 "cmp_fp_expander_operand")
1380                     (match_operand:MODEF 3 "cmp_fp_expander_operand")))
1381    (set (match_operand:QI 0 "register_operand")
1382               (match_operator 1 "ix86_fp_comparison_operator"
1383                [(reg:CC FLAGS_REG)
1384                 (const_int 0)]))]
1385   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1386 {
1387   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1388                      operands[2], operands[3]);
1389   DONE;
1390 })
1391
1392 (define_expand "cbranchcc4"
1393   [(set (pc) (if_then_else
1394               (match_operator 0 "comparison_operator"
1395                [(match_operand 1 "flags_reg_operand")
1396                 (match_operand 2 "const0_operand")])
1397               (label_ref (match_operand 3))
1398               (pc)))]
1399   ""
1400 {
1401   ix86_expand_branch (GET_CODE (operands[0]),
1402                       operands[1], operands[2], operands[3]);
1403   DONE;
1404 })
1405
1406 (define_expand "cstorecc4"
1407   [(set (match_operand:QI 0 "register_operand")
1408               (match_operator 1 "comparison_operator"
1409                [(match_operand 2 "flags_reg_operand")
1410                 (match_operand 3 "const0_operand")]))]
1411   ""
1412 {
1413   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1414                      operands[2], operands[3]);
1415   DONE;
1416 })
1417
1418
1419 ;; FP compares, step 1:
1420 ;; Set the FP condition codes.
1421 ;;
1422 ;; CCFPmode     compare with exceptions
1423 ;; CCFPUmode    compare with no exceptions
1424
1425 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
1426 ;; used to manage the reg stack popping would not be preserved.
1427
1428 (define_insn "*cmp<mode>_0_i387"
1429   [(set (match_operand:HI 0 "register_operand" "=a")
1430         (unspec:HI
1431           [(compare:CCFP
1432              (match_operand:X87MODEF 1 "register_operand" "f")
1433              (match_operand:X87MODEF 2 "const0_operand"))]
1434         UNSPEC_FNSTSW))]
1435   "TARGET_80387"
1436   "* return output_fp_compare (insn, operands, false, false);"
1437   [(set_attr "type" "multi")
1438    (set_attr "unit" "i387")
1439    (set_attr "mode" "<MODE>")])
1440
1441 (define_insn_and_split "*cmp<mode>_0_cc_i387"
1442   [(set (reg:CCFP FLAGS_REG)
1443         (compare:CCFP
1444           (match_operand:X87MODEF 1 "register_operand" "f")
1445           (match_operand:X87MODEF 2 "const0_operand")))
1446    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1447   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1448   "#"
1449   "&& reload_completed"
1450   [(set (match_dup 0)
1451         (unspec:HI
1452           [(compare:CCFP (match_dup 1)(match_dup 2))]
1453         UNSPEC_FNSTSW))
1454    (set (reg:CC FLAGS_REG)
1455         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1456   ""
1457   [(set_attr "type" "multi")
1458    (set_attr "unit" "i387")
1459    (set_attr "mode" "<MODE>")])
1460
1461 (define_insn "*cmpxf_i387"
1462   [(set (match_operand:HI 0 "register_operand" "=a")
1463         (unspec:HI
1464           [(compare:CCFP
1465              (match_operand:XF 1 "register_operand" "f")
1466              (match_operand:XF 2 "register_operand" "f"))]
1467           UNSPEC_FNSTSW))]
1468   "TARGET_80387"
1469   "* return output_fp_compare (insn, operands, false, false);"
1470   [(set_attr "type" "multi")
1471    (set_attr "unit" "i387")
1472    (set_attr "mode" "XF")])
1473
1474 (define_insn_and_split "*cmpxf_cc_i387"
1475   [(set (reg:CCFP FLAGS_REG)
1476         (compare:CCFP
1477           (match_operand:XF 1 "register_operand" "f")
1478           (match_operand:XF 2 "register_operand" "f")))
1479    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1480   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1481   "#"
1482   "&& reload_completed"
1483   [(set (match_dup 0)
1484         (unspec:HI
1485           [(compare:CCFP (match_dup 1)(match_dup 2))]
1486         UNSPEC_FNSTSW))
1487    (set (reg:CC FLAGS_REG)
1488         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1489   ""
1490   [(set_attr "type" "multi")
1491    (set_attr "unit" "i387")
1492    (set_attr "mode" "XF")])
1493
1494 (define_insn "*cmp<mode>_i387"
1495   [(set (match_operand:HI 0 "register_operand" "=a")
1496         (unspec:HI
1497           [(compare:CCFP
1498              (match_operand:MODEF 1 "register_operand" "f")
1499              (match_operand:MODEF 2 "nonimmediate_operand" "fm"))]
1500           UNSPEC_FNSTSW))]
1501   "TARGET_80387"
1502   "* return output_fp_compare (insn, operands, false, false);"
1503   [(set_attr "type" "multi")
1504    (set_attr "unit" "i387")
1505    (set_attr "mode" "<MODE>")])
1506
1507 (define_insn_and_split "*cmp<mode>_cc_i387"
1508   [(set (reg:CCFP FLAGS_REG)
1509         (compare:CCFP
1510           (match_operand:MODEF 1 "register_operand" "f")
1511           (match_operand:MODEF 2 "nonimmediate_operand" "fm")))
1512    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1513   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1514   "#"
1515   "&& reload_completed"
1516   [(set (match_dup 0)
1517         (unspec:HI
1518           [(compare:CCFP (match_dup 1)(match_dup 2))]
1519         UNSPEC_FNSTSW))
1520    (set (reg:CC FLAGS_REG)
1521         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1522   ""
1523   [(set_attr "type" "multi")
1524    (set_attr "unit" "i387")
1525    (set_attr "mode" "<MODE>")])
1526
1527 (define_insn "*cmpu<mode>_i387"
1528   [(set (match_operand:HI 0 "register_operand" "=a")
1529         (unspec:HI
1530           [(compare:CCFPU
1531              (match_operand:X87MODEF 1 "register_operand" "f")
1532              (match_operand:X87MODEF 2 "register_operand" "f"))]
1533           UNSPEC_FNSTSW))]
1534   "TARGET_80387"
1535   "* return output_fp_compare (insn, operands, false, true);"
1536   [(set_attr "type" "multi")
1537    (set_attr "unit" "i387")
1538    (set_attr "mode" "<MODE>")])
1539
1540 (define_insn_and_split "*cmpu<mode>_cc_i387"
1541   [(set (reg:CCFPU FLAGS_REG)
1542         (compare:CCFPU
1543           (match_operand:X87MODEF 1 "register_operand" "f")
1544           (match_operand:X87MODEF 2 "register_operand" "f")))
1545    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1546   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1547   "#"
1548   "&& reload_completed"
1549   [(set (match_dup 0)
1550         (unspec:HI
1551           [(compare:CCFPU (match_dup 1)(match_dup 2))]
1552         UNSPEC_FNSTSW))
1553    (set (reg:CC FLAGS_REG)
1554         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1555   ""
1556   [(set_attr "type" "multi")
1557    (set_attr "unit" "i387")
1558    (set_attr "mode" "<MODE>")])
1559
1560 (define_insn "*cmp<X87MODEF:mode>_<SWI24:mode>_i387"
1561   [(set (match_operand:HI 0 "register_operand" "=a")
1562         (unspec:HI
1563           [(compare:CCFP
1564              (match_operand:X87MODEF 1 "register_operand" "f")
1565              (match_operator:X87MODEF 3 "float_operator"
1566                [(match_operand:SWI24 2 "memory_operand" "m")]))]
1567           UNSPEC_FNSTSW))]
1568   "TARGET_80387
1569    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
1570        || optimize_function_for_size_p (cfun))"
1571   "* return output_fp_compare (insn, operands, false, false);"
1572   [(set_attr "type" "multi")
1573    (set_attr "unit" "i387")
1574    (set_attr "fp_int_src" "true")
1575    (set_attr "mode" "<SWI24:MODE>")])
1576
1577 (define_insn_and_split "*cmp<X87MODEF:mode>_<SWI24:mode>_cc_i387"
1578   [(set (reg:CCFP FLAGS_REG)
1579         (compare:CCFP
1580           (match_operand:X87MODEF 1 "register_operand" "f")
1581           (match_operator:X87MODEF 3 "float_operator"
1582             [(match_operand:SWI24 2 "memory_operand" "m")])))
1583    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1584   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE
1585    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
1586        || optimize_function_for_size_p (cfun))"
1587   "#"
1588   "&& reload_completed"
1589   [(set (match_dup 0)
1590         (unspec:HI
1591           [(compare:CCFP
1592              (match_dup 1)
1593              (match_op_dup 3 [(match_dup 2)]))]
1594         UNSPEC_FNSTSW))
1595    (set (reg:CC FLAGS_REG)
1596         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1597   ""
1598   [(set_attr "type" "multi")
1599    (set_attr "unit" "i387")
1600    (set_attr "fp_int_src" "true")
1601    (set_attr "mode" "<SWI24:MODE>")])
1602
1603 ;; FP compares, step 2
1604 ;; Move the fpsw to ax.
1605
1606 (define_insn "x86_fnstsw_1"
1607   [(set (match_operand:HI 0 "register_operand" "=a")
1608         (unspec:HI [(reg:CCFP FPSR_REG)] UNSPEC_FNSTSW))]
1609   "TARGET_80387"
1610   "fnstsw\t%0"
1611   [(set_attr "length" "2")
1612    (set_attr "mode" "SI")
1613    (set_attr "unit" "i387")])
1614
1615 ;; FP compares, step 3
1616 ;; Get ax into flags, general case.
1617
1618 (define_insn "x86_sahf_1"
1619   [(set (reg:CC FLAGS_REG)
1620         (unspec:CC [(match_operand:HI 0 "register_operand" "a")]
1621                    UNSPEC_SAHF))]
1622   "TARGET_SAHF"
1623 {
1624 #ifndef HAVE_AS_IX86_SAHF
1625   if (TARGET_64BIT)
1626     return ASM_BYTE "0x9e";
1627   else
1628 #endif
1629   return "sahf";
1630 }
1631   [(set_attr "length" "1")
1632    (set_attr "athlon_decode" "vector")
1633    (set_attr "amdfam10_decode" "direct")
1634    (set_attr "bdver1_decode" "direct")
1635    (set_attr "mode" "SI")])
1636
1637 ;; Pentium Pro can do steps 1 through 3 in one go.
1638 ;; comi*, ucomi*, fcomi*, ficomi*, fucomi*
1639 ;; (these i387 instructions set flags directly)
1640
1641 (define_mode_iterator FPCMP [CCFP CCFPU])
1642 (define_mode_attr unord [(CCFP "") (CCFPU "u")])
1643
1644 (define_insn "*cmpi<FPCMP:unord><MODEF:mode>_mixed"
1645   [(set (reg:FPCMP FLAGS_REG)
1646         (compare:FPCMP
1647           (match_operand:MODEF 0 "register_operand" "f,x")
1648           (match_operand:MODEF 1 "nonimmediate_operand" "f,xm")))]
1649   "TARGET_MIX_SSE_I387
1650    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode)"
1651   "* return output_fp_compare (insn, operands, true,
1652                                <FPCMP:MODE>mode == CCFPUmode);"
1653   [(set_attr "type" "fcmp,ssecomi")
1654    (set_attr "prefix" "orig,maybe_vex")
1655    (set_attr "mode" "<MODEF:MODE>")
1656    (set (attr "prefix_rep")
1657         (if_then_else (eq_attr "type" "ssecomi")
1658                       (const_string "0")
1659                       (const_string "*")))
1660    (set (attr "prefix_data16")
1661         (cond [(eq_attr "type" "fcmp")
1662                  (const_string "*")
1663                (eq_attr "mode" "DF")
1664                  (const_string "1")
1665               ]
1666               (const_string "0")))
1667    (set_attr "athlon_decode" "vector")
1668    (set_attr "amdfam10_decode" "direct")
1669    (set_attr "bdver1_decode" "double")])
1670
1671 (define_insn "*cmpi<FPCMP:unord><MODEF:mode>_sse"
1672   [(set (reg:FPCMP FLAGS_REG)
1673         (compare:FPCMP
1674           (match_operand:MODEF 0 "register_operand" "x")
1675           (match_operand:MODEF 1 "nonimmediate_operand" "xm")))]
1676   "TARGET_SSE_MATH
1677    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode)"
1678   "* return output_fp_compare (insn, operands, true,
1679                                <FPCMP:MODE>mode == CCFPUmode);"
1680   [(set_attr "type" "ssecomi")
1681    (set_attr "prefix" "maybe_vex")
1682    (set_attr "mode" "<MODEF:MODE>")
1683    (set_attr "prefix_rep" "0")
1684    (set (attr "prefix_data16")
1685         (if_then_else (eq_attr "mode" "DF")
1686                       (const_string "1")
1687                       (const_string "0")))
1688    (set_attr "athlon_decode" "vector")
1689    (set_attr "amdfam10_decode" "direct")
1690    (set_attr "bdver1_decode" "double")])
1691
1692 (define_insn "*cmpi<FPCMP:unord><X87MODEF:mode>_i387"
1693   [(set (reg:FPCMP FLAGS_REG)
1694         (compare:FPCMP
1695           (match_operand:X87MODEF 0 "register_operand" "f")
1696           (match_operand:X87MODEF 1 "register_operand" "f")))]
1697   "TARGET_80387 && TARGET_CMOVE
1698    && !(SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)"
1699   "* return output_fp_compare (insn, operands, true,
1700                                <FPCMP:MODE>mode == CCFPUmode);"
1701   [(set_attr "type" "fcmp")
1702    (set_attr "mode" "<X87MODEF:MODE>")
1703    (set_attr "athlon_decode" "vector")
1704    (set_attr "amdfam10_decode" "direct")
1705    (set_attr "bdver1_decode" "double")])
1706 \f
1707 ;; Push/pop instructions.
1708
1709 (define_insn "*push<mode>2"
1710   [(set (match_operand:DWI 0 "push_operand" "=<")
1711         (match_operand:DWI 1 "general_no_elim_operand" "riF*o"))]
1712   ""
1713   "#"
1714   [(set_attr "type" "multi")
1715    (set_attr "mode" "<MODE>")])
1716
1717 (define_split
1718   [(set (match_operand:TI 0 "push_operand")
1719         (match_operand:TI 1 "general_operand"))]
1720   "TARGET_64BIT && reload_completed
1721    && !SSE_REG_P (operands[1])"
1722   [(const_int 0)]
1723   "ix86_split_long_move (operands); DONE;")
1724
1725 (define_insn "*pushdi2_rex64"
1726   [(set (match_operand:DI 0 "push_operand" "=<,!<")
1727         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
1728   "TARGET_64BIT"
1729   "@
1730    push{q}\t%1
1731    #"
1732   [(set_attr "type" "push,multi")
1733    (set_attr "mode" "DI")])
1734
1735 ;; Convert impossible pushes of immediate to existing instructions.
1736 ;; First try to get scratch register and go through it.  In case this
1737 ;; fails, push sign extended lower part first and then overwrite
1738 ;; upper part by 32bit move.
1739 (define_peephole2
1740   [(match_scratch:DI 2 "r")
1741    (set (match_operand:DI 0 "push_operand")
1742         (match_operand:DI 1 "immediate_operand"))]
1743   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1744    && !x86_64_immediate_operand (operands[1], DImode)"
1745   [(set (match_dup 2) (match_dup 1))
1746    (set (match_dup 0) (match_dup 2))])
1747
1748 ;; We need to define this as both peepholer and splitter for case
1749 ;; peephole2 pass is not run.
1750 ;; "&& 1" is needed to keep it from matching the previous pattern.
1751 (define_peephole2
1752   [(set (match_operand:DI 0 "push_operand")
1753         (match_operand:DI 1 "immediate_operand"))]
1754   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1755    && !x86_64_immediate_operand (operands[1], DImode) && 1"
1756   [(set (match_dup 0) (match_dup 1))
1757    (set (match_dup 2) (match_dup 3))]
1758 {
1759   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1760
1761   operands[1] = gen_lowpart (DImode, operands[2]);
1762   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (Pmode, stack_pointer_rtx,
1763                                                    GEN_INT (4)));
1764 })
1765
1766 (define_split
1767   [(set (match_operand:DI 0 "push_operand")
1768         (match_operand:DI 1 "immediate_operand"))]
1769   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
1770                     ? epilogue_completed : reload_completed)
1771    && !symbolic_operand (operands[1], DImode)
1772    && !x86_64_immediate_operand (operands[1], DImode)"
1773   [(set (match_dup 0) (match_dup 1))
1774    (set (match_dup 2) (match_dup 3))]
1775 {
1776   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1777
1778   operands[1] = gen_lowpart (DImode, operands[2]);
1779   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (Pmode, stack_pointer_rtx,
1780                                                    GEN_INT (4)));
1781 })
1782
1783 (define_split
1784   [(set (match_operand:DI 0 "push_operand")
1785         (match_operand:DI 1 "general_operand"))]
1786   "!TARGET_64BIT && reload_completed
1787    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
1788   [(const_int 0)]
1789   "ix86_split_long_move (operands); DONE;")
1790
1791 (define_insn "*pushsi2"
1792   [(set (match_operand:SI 0 "push_operand" "=<")
1793         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1794   "!TARGET_64BIT"
1795   "push{l}\t%1"
1796   [(set_attr "type" "push")
1797    (set_attr "mode" "SI")])
1798
1799 ;; emit_push_insn when it calls move_by_pieces requires an insn to
1800 ;; "push a byte/word".  But actually we use pushl, which has the effect
1801 ;; of rounding the amount pushed up to a word.
1802
1803 ;; For TARGET_64BIT we always round up to 8 bytes.
1804 (define_insn "*push<mode>2_rex64"
1805   [(set (match_operand:SWI124 0 "push_operand" "=X")
1806         (match_operand:SWI124 1 "nonmemory_no_elim_operand" "r<i>"))]
1807   "TARGET_64BIT"
1808   "push{q}\t%q1"
1809   [(set_attr "type" "push")
1810    (set_attr "mode" "DI")])
1811
1812 (define_insn "*push<mode>2"
1813   [(set (match_operand:SWI12 0 "push_operand" "=X")
1814         (match_operand:SWI12 1 "nonmemory_no_elim_operand" "rn"))]
1815   "!TARGET_64BIT"
1816   "push{l}\t%k1"
1817   [(set_attr "type" "push")
1818    (set_attr "mode" "SI")])
1819
1820 (define_insn "*push<mode>2_prologue"
1821   [(set (match_operand:W 0 "push_operand" "=<")
1822         (match_operand:W 1 "general_no_elim_operand" "r<i>*m"))
1823    (clobber (mem:BLK (scratch)))]
1824   ""
1825   "push{<imodesuffix>}\t%1"
1826   [(set_attr "type" "push")
1827    (set_attr "mode" "<MODE>")])
1828
1829 (define_insn "*pop<mode>1"
1830   [(set (match_operand:W 0 "nonimmediate_operand" "=r*m")
1831         (match_operand:W 1 "pop_operand" ">"))]
1832   ""
1833   "pop{<imodesuffix>}\t%0"
1834   [(set_attr "type" "pop")
1835    (set_attr "mode" "<MODE>")])
1836
1837 (define_insn "*pop<mode>1_epilogue"
1838   [(set (match_operand:W 0 "nonimmediate_operand" "=r*m")
1839         (match_operand:W 1 "pop_operand" ">"))
1840    (clobber (mem:BLK (scratch)))]
1841   ""
1842   "pop{<imodesuffix>}\t%0"
1843   [(set_attr "type" "pop")
1844    (set_attr "mode" "<MODE>")])
1845
1846 (define_insn "*pushfl<mode>2"
1847   [(set (match_operand:W 0 "push_operand" "=<")
1848         (match_operand:W 1 "flags_reg_operand"))]
1849   ""
1850   "pushf{<imodesuffix>}"
1851   [(set_attr "type" "push")
1852    (set_attr "mode" "<MODE>")])
1853
1854 (define_insn "*popfl<mode>1"
1855   [(set (match_operand:W 0 "flags_reg_operand")
1856         (match_operand:W 1 "pop_operand" ">"))]
1857   ""
1858   "popf{<imodesuffix>}"
1859   [(set_attr "type" "pop")
1860    (set_attr "mode" "<MODE>")])
1861
1862 \f
1863 ;; Move instructions.
1864
1865 (define_expand "movxi"
1866   [(set (match_operand:XI 0 "nonimmediate_operand")
1867         (match_operand:XI 1 "general_operand"))]
1868   "TARGET_AVX512F"
1869   "ix86_expand_move (XImode, operands); DONE;")
1870
1871 ;; Reload patterns to support multi-word load/store
1872 ;; with non-offsetable address.
1873 (define_expand "reload_noff_store"
1874   [(parallel [(match_operand 0 "memory_operand" "=m")
1875               (match_operand 1 "register_operand" "r")
1876               (match_operand:DI 2 "register_operand" "=&r")])]
1877   "TARGET_64BIT"
1878 {
1879   rtx mem = operands[0];
1880   rtx addr = XEXP (mem, 0);
1881
1882   emit_move_insn (operands[2], addr);
1883   mem = replace_equiv_address_nv (mem, operands[2]);
1884
1885   emit_insn (gen_rtx_SET (VOIDmode, mem, operands[1]));
1886   DONE;
1887 })
1888
1889 (define_expand "reload_noff_load"
1890   [(parallel [(match_operand 0 "register_operand" "=r")
1891               (match_operand 1 "memory_operand" "m")
1892               (match_operand:DI 2 "register_operand" "=r")])]
1893   "TARGET_64BIT"
1894 {
1895   rtx mem = operands[1];
1896   rtx addr = XEXP (mem, 0);
1897
1898   emit_move_insn (operands[2], addr);
1899   mem = replace_equiv_address_nv (mem, operands[2]);
1900
1901   emit_insn (gen_rtx_SET (VOIDmode, operands[0], mem));
1902   DONE;
1903 })
1904
1905 (define_expand "movoi"
1906   [(set (match_operand:OI 0 "nonimmediate_operand")
1907         (match_operand:OI 1 "general_operand"))]
1908   "TARGET_AVX"
1909   "ix86_expand_move (OImode, operands); DONE;")
1910
1911 (define_expand "movti"
1912   [(set (match_operand:TI 0 "nonimmediate_operand")
1913         (match_operand:TI 1 "nonimmediate_operand"))]
1914   "TARGET_64BIT || TARGET_SSE"
1915 {
1916   if (TARGET_64BIT)
1917     ix86_expand_move (TImode, operands);
1918   else
1919     ix86_expand_vector_move (TImode, operands);
1920   DONE;
1921 })
1922
1923 ;; This expands to what emit_move_complex would generate if we didn't
1924 ;; have a movti pattern.  Having this avoids problems with reload on
1925 ;; 32-bit targets when SSE is present, but doesn't seem to be harmful
1926 ;; to have around all the time.
1927 (define_expand "movcdi"
1928   [(set (match_operand:CDI 0 "nonimmediate_operand")
1929         (match_operand:CDI 1 "general_operand"))]
1930   ""
1931 {
1932   if (push_operand (operands[0], CDImode))
1933     emit_move_complex_push (CDImode, operands[0], operands[1]);
1934   else
1935     emit_move_complex_parts (operands[0], operands[1]);
1936   DONE;
1937 })
1938
1939 (define_expand "mov<mode>"
1940   [(set (match_operand:SWI1248x 0 "nonimmediate_operand")
1941         (match_operand:SWI1248x 1 "general_operand"))]
1942   ""
1943   "ix86_expand_move (<MODE>mode, operands); DONE;")
1944
1945 (define_insn "*mov<mode>_xor"
1946   [(set (match_operand:SWI48 0 "register_operand" "=r")
1947         (match_operand:SWI48 1 "const0_operand"))
1948    (clobber (reg:CC FLAGS_REG))]
1949   "reload_completed"
1950   "xor{l}\t%k0, %k0"
1951   [(set_attr "type" "alu1")
1952    (set_attr "mode" "SI")
1953    (set_attr "length_immediate" "0")])
1954
1955 (define_insn "*mov<mode>_or"
1956   [(set (match_operand:SWI48 0 "register_operand" "=r")
1957         (match_operand:SWI48 1 "const_int_operand"))
1958    (clobber (reg:CC FLAGS_REG))]
1959   "reload_completed
1960    && operands[1] == constm1_rtx"
1961   "or{<imodesuffix>}\t{%1, %0|%0, %1}"
1962   [(set_attr "type" "alu1")
1963    (set_attr "mode" "<MODE>")
1964    (set_attr "length_immediate" "1")])
1965
1966 (define_insn "*movxi_internal_avx512f"
1967   [(set (match_operand:XI 0 "nonimmediate_operand" "=x,x ,m")
1968         (match_operand:XI 1 "vector_move_operand"  "C ,xm,x"))]
1969   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1970 {
1971   switch (which_alternative)
1972     {
1973     case 0:
1974       return standard_sse_constant_opcode (insn, operands[1]);
1975     case 1:
1976     case 2:
1977       if (misaligned_operand (operands[0], XImode)
1978           || misaligned_operand (operands[1], XImode))
1979         return "vmovdqu32\t{%1, %0|%0, %1}";
1980       else
1981         return "vmovdqa32\t{%1, %0|%0, %1}";
1982     default:
1983       gcc_unreachable ();
1984     }
1985 }
1986   [(set_attr "type" "sselog1,ssemov,ssemov")
1987    (set_attr "prefix" "evex")
1988    (set_attr "mode" "XI")])
1989
1990 (define_insn "*movoi_internal_avx"
1991   [(set (match_operand:OI 0 "nonimmediate_operand" "=v,v ,m")
1992         (match_operand:OI 1 "vector_move_operand"  "C ,vm,v"))]
1993   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1994 {
1995   switch (get_attr_type (insn))
1996     {
1997     case TYPE_SSELOG1:
1998       return standard_sse_constant_opcode (insn, operands[1]);
1999
2000     case TYPE_SSEMOV:
2001       if (misaligned_operand (operands[0], OImode)
2002           || misaligned_operand (operands[1], OImode))
2003         {
2004           if (get_attr_mode (insn) == MODE_V8SF)
2005             return "vmovups\t{%1, %0|%0, %1}";
2006           else if (get_attr_mode (insn) == MODE_XI)
2007             return "vmovdqu32\t{%1, %0|%0, %1}";
2008           else
2009             return "vmovdqu\t{%1, %0|%0, %1}";
2010         }
2011       else
2012         {
2013           if (get_attr_mode (insn) == MODE_V8SF)
2014             return "vmovaps\t{%1, %0|%0, %1}";
2015           else if (get_attr_mode (insn) == MODE_XI)
2016             return "vmovdqa32\t{%1, %0|%0, %1}";
2017           else
2018             return "vmovdqa\t{%1, %0|%0, %1}";
2019         }
2020
2021     default:
2022       gcc_unreachable ();
2023     }
2024 }
2025   [(set_attr "type" "sselog1,ssemov,ssemov")
2026    (set_attr "prefix" "vex")
2027    (set (attr "mode")
2028         (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2029                     (match_operand 1 "ext_sse_reg_operand"))
2030                  (const_string "XI")
2031                (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
2032                  (const_string "V8SF")
2033                (and (eq_attr "alternative" "2")
2034                     (match_test "TARGET_SSE_TYPELESS_STORES"))
2035                  (const_string "V8SF")
2036               ]
2037               (const_string "OI")))])
2038
2039 (define_insn "*movti_internal"
2040   [(set (match_operand:TI 0 "nonimmediate_operand" "=!r ,o ,v,v ,m")
2041         (match_operand:TI 1 "general_operand"      "riFo,re,C,vm,v"))]
2042   "(TARGET_64BIT || TARGET_SSE)
2043    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2044 {
2045   switch (get_attr_type (insn))
2046     {
2047     case TYPE_MULTI:
2048       return "#";
2049
2050     case TYPE_SSELOG1:
2051       return standard_sse_constant_opcode (insn, operands[1]);
2052
2053     case TYPE_SSEMOV:
2054       /* TDmode values are passed as TImode on the stack.  Moving them
2055          to stack may result in unaligned memory access.  */
2056       if (misaligned_operand (operands[0], TImode)
2057           || misaligned_operand (operands[1], TImode))
2058         {
2059           if (get_attr_mode (insn) == MODE_V4SF)
2060             return "%vmovups\t{%1, %0|%0, %1}";
2061           else if (get_attr_mode (insn) == MODE_XI)
2062             return "vmovdqu32\t{%1, %0|%0, %1}";
2063           else
2064             return "%vmovdqu\t{%1, %0|%0, %1}";
2065         }
2066       else
2067         {
2068           if (get_attr_mode (insn) == MODE_V4SF)
2069             return "%vmovaps\t{%1, %0|%0, %1}";
2070           else if (get_attr_mode (insn) == MODE_XI)
2071             return "vmovdqa32\t{%1, %0|%0, %1}";
2072           else
2073             return "%vmovdqa\t{%1, %0|%0, %1}";
2074         }
2075
2076     default:
2077       gcc_unreachable ();
2078     }
2079 }
2080   [(set_attr "isa" "x64,x64,*,*,*")
2081    (set_attr "type" "multi,multi,sselog1,ssemov,ssemov")
2082    (set (attr "prefix")
2083      (if_then_else (eq_attr "type" "sselog1,ssemov")
2084        (const_string "maybe_vex")
2085        (const_string "orig")))
2086    (set (attr "mode")
2087         (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2088                     (match_operand 1 "ext_sse_reg_operand"))
2089                  (const_string "XI")
2090                (eq_attr "alternative" "0,1")
2091                  (const_string "DI")
2092                (ior (not (match_test "TARGET_SSE2"))
2093                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2094                  (const_string "V4SF")
2095                (and (eq_attr "alternative" "4")
2096                     (match_test "TARGET_SSE_TYPELESS_STORES"))
2097                  (const_string "V4SF")
2098                (match_test "TARGET_AVX")
2099                  (const_string "TI")
2100                (match_test "optimize_function_for_size_p (cfun)")
2101                  (const_string "V4SF")
2102                ]
2103                (const_string "TI")))])
2104
2105 (define_split
2106   [(set (match_operand:TI 0 "nonimmediate_operand")
2107         (match_operand:TI 1 "general_operand"))]
2108   "reload_completed
2109    && !SSE_REG_P (operands[0]) && !SSE_REG_P (operands[1])"
2110   [(const_int 0)]
2111   "ix86_split_long_move (operands); DONE;")
2112
2113 (define_insn "*movdi_internal"
2114   [(set (match_operand:DI 0 "nonimmediate_operand"
2115     "=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")
2116         (match_operand:DI 1 "general_operand"
2117     "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"))]
2118   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2119 {
2120   switch (get_attr_type (insn))
2121     {
2122     case TYPE_MSKMOV:
2123       return "kmovq\t{%1, %0|%0, %1}";
2124
2125     case TYPE_MULTI:
2126       return "#";
2127
2128     case TYPE_MMX:
2129       return "pxor\t%0, %0";
2130
2131     case TYPE_MMXMOV:
2132       /* Handle broken assemblers that require movd instead of movq.  */
2133       if (!HAVE_AS_IX86_INTERUNIT_MOVQ
2134           && (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1])))
2135         return "movd\t{%1, %0|%0, %1}";
2136       return "movq\t{%1, %0|%0, %1}";
2137
2138     case TYPE_SSELOG1:
2139       if (GENERAL_REG_P (operands[0]))
2140         return "%vpextrq\t{$0, %1, %0|%0, %1, 0}";
2141
2142       return standard_sse_constant_opcode (insn, operands[1]);
2143
2144     case TYPE_SSEMOV:
2145       switch (get_attr_mode (insn))
2146         {
2147         case MODE_DI:
2148           /* Handle broken assemblers that require movd instead of movq.  */
2149           if (!HAVE_AS_IX86_INTERUNIT_MOVQ
2150               && (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1])))
2151             return "%vmovd\t{%1, %0|%0, %1}";
2152           return "%vmovq\t{%1, %0|%0, %1}";
2153         case MODE_TI:
2154           return "%vmovdqa\t{%1, %0|%0, %1}";
2155         case MODE_XI:
2156           return "vmovdqa64\t{%g1, %g0|%g0, %g1}";
2157
2158         case MODE_V2SF:
2159           gcc_assert (!TARGET_AVX);
2160           return "movlps\t{%1, %0|%0, %1}";
2161         case MODE_V4SF:
2162           return "%vmovaps\t{%1, %0|%0, %1}";
2163
2164         default:
2165           gcc_unreachable ();
2166         }
2167
2168     case TYPE_SSECVT:
2169       if (SSE_REG_P (operands[0]))
2170         return "movq2dq\t{%1, %0|%0, %1}";
2171       else
2172         return "movdq2q\t{%1, %0|%0, %1}";
2173
2174     case TYPE_LEA:
2175       return "lea{q}\t{%E1, %0|%0, %E1}";
2176
2177     case TYPE_IMOV:
2178       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2179       if (get_attr_mode (insn) == MODE_SI)
2180         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2181       else if (which_alternative == 4)
2182         return "movabs{q}\t{%1, %0|%0, %1}";
2183       else if (ix86_use_lea_for_mov (insn, operands))
2184         return "lea{q}\t{%E1, %0|%0, %E1}";
2185       else
2186         return "mov{q}\t{%1, %0|%0, %1}";
2187
2188     default:
2189       gcc_unreachable ();
2190     }
2191 }
2192   [(set (attr "isa")
2193      (cond [(eq_attr "alternative" "0,1")
2194               (const_string "nox64")
2195             (eq_attr "alternative" "2,3,4,5,10,11,16,18,21,23")
2196               (const_string "x64")
2197             (eq_attr "alternative" "17")
2198               (const_string "x64_sse4")
2199            ]
2200            (const_string "*")))
2201    (set (attr "type")
2202      (cond [(eq_attr "alternative" "0,1")
2203               (const_string "multi")
2204             (eq_attr "alternative" "6")
2205               (const_string "mmx")
2206             (eq_attr "alternative" "7,8,9,10,11")
2207               (const_string "mmxmov")
2208             (eq_attr "alternative" "12,17")
2209               (const_string "sselog1")
2210             (eq_attr "alternative" "13,14,15,16,18")
2211               (const_string "ssemov")
2212             (eq_attr "alternative" "19,20")
2213               (const_string "ssecvt")
2214             (eq_attr "alternative" "21,22,23,24")
2215               (const_string "mskmov")
2216             (and (match_operand 0 "register_operand")
2217                  (match_operand 1 "pic_32bit_operand"))
2218               (const_string "lea")
2219            ]
2220            (const_string "imov")))
2221    (set (attr "modrm")
2222      (if_then_else
2223        (and (eq_attr "alternative" "4") (eq_attr "type" "imov"))
2224          (const_string "0")
2225          (const_string "*")))
2226    (set (attr "length_immediate")
2227      (cond [(and (eq_attr "alternative" "4") (eq_attr "type" "imov"))
2228               (const_string "8")
2229             (eq_attr "alternative" "17")
2230               (const_string "1")
2231            ]
2232            (const_string "*")))
2233    (set (attr "prefix_rex")
2234      (if_then_else (eq_attr "alternative" "10,11,16,17,18")
2235        (const_string "1")
2236        (const_string "*")))
2237    (set (attr "prefix_extra")
2238      (if_then_else (eq_attr "alternative" "17")
2239        (const_string "1")
2240        (const_string "*")))
2241    (set (attr "prefix")
2242      (if_then_else (eq_attr "type" "sselog1,ssemov")
2243        (const_string "maybe_vex")
2244        (const_string "orig")))
2245    (set (attr "prefix_data16")
2246      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "DI"))
2247        (const_string "1")
2248        (const_string "*")))
2249    (set (attr "mode")
2250      (cond [(eq_attr "alternative" "2")
2251               (const_string "SI")
2252             (eq_attr "alternative" "12,13")
2253               (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2254                           (match_operand 1 "ext_sse_reg_operand"))
2255                        (const_string "XI")
2256                      (ior (not (match_test "TARGET_SSE2"))
2257                           (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2258                        (const_string "V4SF")
2259                      (match_test "TARGET_AVX")
2260                        (const_string "TI")
2261                      (match_test "optimize_function_for_size_p (cfun)")
2262                        (const_string "V4SF")
2263                     ]
2264                     (const_string "TI"))
2265
2266             (and (eq_attr "alternative" "14,15")
2267                  (not (match_test "TARGET_SSE2")))
2268               (const_string "V2SF")
2269             (eq_attr "alternative" "17")
2270               (const_string "TI")
2271            ]
2272            (const_string "DI")))])
2273
2274 (define_split
2275   [(set (match_operand:DI 0 "nonimmediate_operand")
2276         (match_operand:DI 1 "general_operand"))]
2277   "!TARGET_64BIT && reload_completed
2278    && !(MMX_REG_P (operands[0])
2279         || SSE_REG_P (operands[0])
2280         || MASK_REG_P (operands[0]))
2281    && !(MMX_REG_P (operands[1])
2282         || SSE_REG_P (operands[1])
2283         || MASK_REG_P (operands[1]))"
2284   [(const_int 0)]
2285   "ix86_split_long_move (operands); DONE;")
2286
2287 (define_insn "*movsi_internal"
2288   [(set (match_operand:SI 0 "nonimmediate_operand"
2289                         "=r,m ,*y,*y,?rm,?*y,*v,*v,*v,m ,?r ,?r,?*Yi,*k  ,*rm")
2290         (match_operand:SI 1 "general_operand"
2291                         "g ,re,C ,*y,*y ,rm ,C ,*v,m ,*v,*Yj,*v,r   ,*krm,*k"))]
2292   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2293 {
2294   switch (get_attr_type (insn))
2295     {
2296     case TYPE_SSELOG1:
2297       if (GENERAL_REG_P (operands[0]))
2298         return "%vpextrd\t{$0, %1, %0|%0, %1, 0}";
2299
2300       return standard_sse_constant_opcode (insn, operands[1]);
2301
2302     case TYPE_MSKMOV:
2303       return "kmovd\t{%1, %0|%0, %1}";
2304
2305     case TYPE_SSEMOV:
2306       switch (get_attr_mode (insn))
2307         {
2308         case MODE_SI:
2309           return "%vmovd\t{%1, %0|%0, %1}";
2310         case MODE_TI:
2311           return "%vmovdqa\t{%1, %0|%0, %1}";
2312         case MODE_XI:
2313           return "vmovdqa32\t{%g1, %g0|%g0, %g1}";
2314
2315         case MODE_V4SF:
2316           return "%vmovaps\t{%1, %0|%0, %1}";
2317
2318         case MODE_SF:
2319           gcc_assert (!TARGET_AVX);
2320           return "movss\t{%1, %0|%0, %1}";
2321
2322         default:
2323           gcc_unreachable ();
2324         }
2325
2326     case TYPE_MMX:
2327       return "pxor\t%0, %0";
2328
2329     case TYPE_MMXMOV:
2330       switch (get_attr_mode (insn))
2331         {
2332         case MODE_DI:
2333           return "movq\t{%1, %0|%0, %1}";
2334         case MODE_SI:
2335           return "movd\t{%1, %0|%0, %1}";
2336
2337         default:
2338           gcc_unreachable ();
2339         }
2340
2341     case TYPE_LEA:
2342       return "lea{l}\t{%E1, %0|%0, %E1}";
2343
2344     case TYPE_IMOV:
2345       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2346       if (ix86_use_lea_for_mov (insn, operands))
2347         return "lea{l}\t{%E1, %0|%0, %E1}";
2348       else
2349         return "mov{l}\t{%1, %0|%0, %1}";
2350
2351     default:
2352       gcc_unreachable ();
2353     }
2354 }
2355   [(set (attr "isa")
2356      (if_then_else (eq_attr "alternative" "11")
2357        (const_string "sse4")
2358        (const_string "*")))
2359    (set (attr "type")
2360      (cond [(eq_attr "alternative" "2")
2361               (const_string "mmx")
2362             (eq_attr "alternative" "3,4,5")
2363               (const_string "mmxmov")
2364             (eq_attr "alternative" "6,11")
2365               (const_string "sselog1")
2366             (eq_attr "alternative" "7,8,9,10,12")
2367               (const_string "ssemov")
2368             (eq_attr "alternative" "13,14")
2369               (const_string "mskmov")
2370             (and (match_operand 0 "register_operand")
2371                  (match_operand 1 "pic_32bit_operand"))
2372               (const_string "lea")
2373            ]
2374            (const_string "imov")))
2375    (set (attr "length_immediate")
2376      (if_then_else (eq_attr "alternative" "11")
2377        (const_string "1")
2378        (const_string "*")))
2379    (set (attr "prefix_extra")
2380      (if_then_else (eq_attr "alternative" "11")
2381        (const_string "1")
2382        (const_string "*")))
2383    (set (attr "prefix")
2384      (if_then_else (eq_attr "type" "sselog1,ssemov")
2385        (const_string "maybe_vex")
2386        (const_string "orig")))
2387    (set (attr "prefix_data16")
2388      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
2389        (const_string "1")
2390        (const_string "*")))
2391    (set (attr "mode")
2392      (cond [(eq_attr "alternative" "2,3")
2393               (const_string "DI")
2394             (eq_attr "alternative" "6,7")
2395               (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2396                           (match_operand 1 "ext_sse_reg_operand"))
2397                        (const_string "XI")
2398                      (ior (not (match_test "TARGET_SSE2"))
2399                           (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2400                        (const_string "V4SF")
2401                      (match_test "TARGET_AVX")
2402                        (const_string "TI")
2403                      (match_test "optimize_function_for_size_p (cfun)")
2404                        (const_string "V4SF")
2405                     ]
2406                     (const_string "TI"))
2407
2408             (and (eq_attr "alternative" "8,9")
2409                  (not (match_test "TARGET_SSE2")))
2410               (const_string "SF")
2411             (eq_attr "alternative" "11")
2412               (const_string "TI")
2413            ]
2414            (const_string "SI")))])
2415
2416 (define_insn "kmovw"
2417   [(set (match_operand:HI 0 "nonimmediate_operand" "=k,k")
2418         (unspec:HI
2419           [(match_operand:HI 1 "nonimmediate_operand" "rm,k")]
2420           UNSPEC_KMOV))]
2421   "!(MEM_P (operands[0]) && MEM_P (operands[1])) && TARGET_AVX512F"
2422   "@
2423    kmovw\t{%k1, %0|%0, %k1}
2424    kmovw\t{%1, %0|%0, %1}";
2425   [(set_attr "mode" "HI")
2426    (set_attr "type" "mskmov")
2427    (set_attr "prefix" "vex")])
2428
2429
2430 (define_insn "*movhi_internal"
2431   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r ,r ,m ,k,k,rm")
2432         (match_operand:HI 1 "general_operand"      "r ,rn,rm,rn,rm,k,k"))]
2433   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2434 {
2435   switch (get_attr_type (insn))
2436     {
2437     case TYPE_IMOVX:
2438       /* movzwl is faster than movw on p2 due to partial word stalls,
2439          though not as fast as an aligned movl.  */
2440       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
2441
2442     case TYPE_MSKMOV:
2443       switch (which_alternative)
2444         {
2445         case 4: return "kmovw\t{%k1, %0|%0, %k1}";
2446         case 5: return "kmovw\t{%1, %0|%0, %1}";
2447         case 6: return "kmovw\t{%1, %k0|%k0, %1}";
2448         default: gcc_unreachable ();
2449         }
2450
2451     default:
2452       if (get_attr_mode (insn) == MODE_SI)
2453         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2454       else
2455         return "mov{w}\t{%1, %0|%0, %1}";
2456     }
2457 }
2458   [(set (attr "type")
2459      (cond [(eq_attr "alternative" "4,5,6")
2460               (const_string "mskmov")
2461             (match_test "optimize_function_for_size_p (cfun)")
2462               (const_string "imov")
2463             (and (eq_attr "alternative" "0")
2464                  (ior (not (match_test "TARGET_PARTIAL_REG_STALL"))
2465                       (not (match_test "TARGET_HIMODE_MATH"))))
2466               (const_string "imov")
2467             (and (eq_attr "alternative" "1,2")
2468                  (match_operand:HI 1 "aligned_operand"))
2469               (const_string "imov")
2470             (and (match_test "TARGET_MOVX")
2471                  (eq_attr "alternative" "0,2"))
2472               (const_string "imovx")
2473            ]
2474            (const_string "imov")))
2475     (set (attr "prefix")
2476       (if_then_else (eq_attr "alternative" "4,5,6")
2477         (const_string "vex")
2478         (const_string "orig")))
2479     (set (attr "mode")
2480       (cond [(eq_attr "type" "imovx")
2481                (const_string "SI")
2482              (and (eq_attr "alternative" "1,2")
2483                   (match_operand:HI 1 "aligned_operand"))
2484                (const_string "SI")
2485              (and (eq_attr "alternative" "0")
2486                   (ior (not (match_test "TARGET_PARTIAL_REG_STALL"))
2487                        (not (match_test "TARGET_HIMODE_MATH"))))
2488                (const_string "SI")
2489             ]
2490             (const_string "HI")))])
2491
2492 ;; Situation is quite tricky about when to choose full sized (SImode) move
2493 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
2494 ;; partial register dependency machines (such as AMD Athlon), where QImode
2495 ;; moves issue extra dependency and for partial register stalls machines
2496 ;; that don't use QImode patterns (and QImode move cause stall on the next
2497 ;; instruction).
2498 ;;
2499 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
2500 ;; register stall machines with, where we use QImode instructions, since
2501 ;; partial register stall can be caused there.  Then we use movzx.
2502
2503 (define_insn "*movqi_internal"
2504   [(set (match_operand:QI 0 "nonimmediate_operand"
2505                         "=q,q ,q ,r,r ,?r,m ,k,k,r ,m,k")
2506         (match_operand:QI 1 "general_operand"
2507                         "q ,qn,qm,q,rn,qm,qn,r ,k,k,k,m"))]
2508   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2509 {
2510   switch (get_attr_type (insn))
2511     {
2512     case TYPE_IMOVX:
2513       gcc_assert (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]));
2514       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
2515
2516     case TYPE_MSKMOV:
2517       switch (which_alternative)
2518         {
2519         case 7: return TARGET_AVX512DQ ? "kmovb\t{%k1, %0|%0, %k1}"
2520                                        : "kmovw\t{%k1, %0|%0, %k1}";
2521         case 8: return TARGET_AVX512DQ ? "kmovb\t{%1, %0|%0, %1}"
2522                                        : "kmovw\t{%1, %0|%0, %1}";
2523         case 9: return TARGET_AVX512DQ ? "kmovb\t{%1, %k0|%k0, %1}"
2524                                        : "kmovw\t{%1, %k0|%k0, %1}";
2525         case 10:
2526         case 11:
2527           gcc_assert (TARGET_AVX512DQ);
2528           return "kmovb\t{%1, %0|%0, %1}";
2529         default: gcc_unreachable ();
2530         }
2531
2532     default:
2533       if (get_attr_mode (insn) == MODE_SI)
2534         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2535       else
2536         return "mov{b}\t{%1, %0|%0, %1}";
2537     }
2538 }
2539   [(set_attr "isa" "*,*,*,*,*,*,*,*,*,*,avx512dq,avx512dq")
2540    (set (attr "type")
2541      (cond [(eq_attr "alternative" "7,8,9,10,11")
2542               (const_string "mskmov")
2543             (and (eq_attr "alternative" "5")
2544                  (not (match_operand:QI 1 "aligned_operand")))
2545               (const_string "imovx")
2546             (match_test "optimize_function_for_size_p (cfun)")
2547               (const_string "imov")
2548             (and (eq_attr "alternative" "3")
2549                  (ior (not (match_test "TARGET_PARTIAL_REG_STALL"))
2550                       (not (match_test "TARGET_QIMODE_MATH"))))
2551               (const_string "imov")
2552             (eq_attr "alternative" "3,5")
2553               (const_string "imovx")
2554             (and (match_test "TARGET_MOVX")
2555                  (eq_attr "alternative" "2"))
2556               (const_string "imovx")
2557            ]
2558            (const_string "imov")))
2559    (set (attr "prefix")
2560      (if_then_else (eq_attr "alternative" "7,8,9")
2561        (const_string "vex")
2562        (const_string "orig")))
2563    (set (attr "mode")
2564       (cond [(eq_attr "alternative" "3,4,5")
2565                (const_string "SI")
2566              (eq_attr "alternative" "6")
2567                (const_string "QI")
2568              (eq_attr "type" "imovx")
2569                (const_string "SI")
2570              (and (eq_attr "type" "imov")
2571                   (and (eq_attr "alternative" "0,1")
2572                        (and (match_test "TARGET_PARTIAL_REG_DEPENDENCY")
2573                             (and (not (match_test "optimize_function_for_size_p (cfun)"))
2574                                  (not (match_test "TARGET_PARTIAL_REG_STALL"))))))
2575                (const_string "SI")
2576              ;; Avoid partial register stalls when not using QImode arithmetic
2577              (and (eq_attr "type" "imov")
2578                   (and (eq_attr "alternative" "0,1")
2579                        (and (match_test "TARGET_PARTIAL_REG_STALL")
2580                             (not (match_test "TARGET_QIMODE_MATH")))))
2581                (const_string "SI")
2582            ]
2583            (const_string "QI")))])
2584
2585 ;; Stores and loads of ax to arbitrary constant address.
2586 ;; We fake an second form of instruction to force reload to load address
2587 ;; into register when rax is not available
2588 (define_insn "*movabs<mode>_1"
2589   [(set (mem:SWI1248x (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2590         (match_operand:SWI1248x 1 "nonmemory_operand" "a,r<i>"))]
2591   "TARGET_LP64 && ix86_check_movabs (insn, 0)"
2592   "@
2593    movabs{<imodesuffix>}\t{%1, %P0|[%P0], %1}
2594    mov{<imodesuffix>}\t{%1, %a0|<iptrsize> PTR %a0, %1}"
2595   [(set_attr "type" "imov")
2596    (set_attr "modrm" "0,*")
2597    (set_attr "length_address" "8,0")
2598    (set_attr "length_immediate" "0,*")
2599    (set_attr "memory" "store")
2600    (set_attr "mode" "<MODE>")])
2601
2602 (define_insn "*movabs<mode>_2"
2603   [(set (match_operand:SWI1248x 0 "register_operand" "=a,r")
2604         (mem:SWI1248x (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2605   "TARGET_LP64 && ix86_check_movabs (insn, 1)"
2606   "@
2607    movabs{<imodesuffix>}\t{%P1, %0|%0, [%P1]}
2608    mov{<imodesuffix>}\t{%a1, %0|%0, <iptrsize> PTR %a1}"
2609   [(set_attr "type" "imov")
2610    (set_attr "modrm" "0,*")
2611    (set_attr "length_address" "8,0")
2612    (set_attr "length_immediate" "0")
2613    (set_attr "memory" "load")
2614    (set_attr "mode" "<MODE>")])
2615
2616 (define_insn "*swap<mode>"
2617   [(set (match_operand:SWI48 0 "register_operand" "+r")
2618         (match_operand:SWI48 1 "register_operand" "+r"))
2619    (set (match_dup 1)
2620         (match_dup 0))]
2621   ""
2622   "xchg{<imodesuffix>}\t%1, %0"
2623   [(set_attr "type" "imov")
2624    (set_attr "mode" "<MODE>")
2625    (set_attr "pent_pair" "np")
2626    (set_attr "athlon_decode" "vector")
2627    (set_attr "amdfam10_decode" "double")
2628    (set_attr "bdver1_decode" "double")])
2629
2630 (define_insn "*swap<mode>_1"
2631   [(set (match_operand:SWI12 0 "register_operand" "+r")
2632         (match_operand:SWI12 1 "register_operand" "+r"))
2633    (set (match_dup 1)
2634         (match_dup 0))]
2635   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
2636   "xchg{l}\t%k1, %k0"
2637   [(set_attr "type" "imov")
2638    (set_attr "mode" "SI")
2639    (set_attr "pent_pair" "np")
2640    (set_attr "athlon_decode" "vector")
2641    (set_attr "amdfam10_decode" "double")
2642    (set_attr "bdver1_decode" "double")])
2643
2644 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL
2645 ;; is disabled for AMDFAM10
2646 (define_insn "*swap<mode>_2"
2647   [(set (match_operand:SWI12 0 "register_operand" "+<r>")
2648         (match_operand:SWI12 1 "register_operand" "+<r>"))
2649    (set (match_dup 1)
2650         (match_dup 0))]
2651   "TARGET_PARTIAL_REG_STALL"
2652   "xchg{<imodesuffix>}\t%1, %0"
2653   [(set_attr "type" "imov")
2654    (set_attr "mode" "<MODE>")
2655    (set_attr "pent_pair" "np")
2656    (set_attr "athlon_decode" "vector")])
2657
2658 (define_expand "movstrict<mode>"
2659   [(set (strict_low_part (match_operand:SWI12 0 "nonimmediate_operand"))
2660         (match_operand:SWI12 1 "general_operand"))]
2661   ""
2662 {
2663   if (TARGET_PARTIAL_REG_STALL && optimize_function_for_speed_p (cfun))
2664     FAIL;
2665   if (GET_CODE (operands[0]) == SUBREG
2666       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (operands[0]))) != MODE_INT)
2667     FAIL;
2668   /* Don't generate memory->memory moves, go through a register */
2669   if (MEM_P (operands[0]) && MEM_P (operands[1]))
2670     operands[1] = force_reg (<MODE>mode, operands[1]);
2671 })
2672
2673 (define_insn "*movstrict<mode>_1"
2674   [(set (strict_low_part
2675           (match_operand:SWI12 0 "nonimmediate_operand" "+<r>m,<r>"))
2676         (match_operand:SWI12 1 "general_operand" "<r>n,m"))]
2677   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
2678    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2679   "mov{<imodesuffix>}\t{%1, %0|%0, %1}"
2680   [(set_attr "type" "imov")
2681    (set_attr "mode" "<MODE>")])
2682
2683 (define_insn "*movstrict<mode>_xor"
2684   [(set (strict_low_part (match_operand:SWI12 0 "register_operand" "+<r>"))
2685         (match_operand:SWI12 1 "const0_operand"))
2686    (clobber (reg:CC FLAGS_REG))]
2687   "reload_completed"
2688   "xor{<imodesuffix>}\t%0, %0"
2689   [(set_attr "type" "alu1")
2690    (set_attr "mode" "<MODE>")
2691    (set_attr "length_immediate" "0")])
2692
2693 (define_insn "*mov<mode>_extv_1"
2694   [(set (match_operand:SWI24 0 "register_operand" "=R")
2695         (sign_extract:SWI24 (match_operand 1 "ext_register_operand" "Q")
2696                             (const_int 8)
2697                             (const_int 8)))]
2698   ""
2699   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
2700   [(set_attr "type" "imovx")
2701    (set_attr "mode" "SI")])
2702
2703 (define_insn "*movqi_extv_1"
2704   [(set (match_operand:QI 0 "nonimmediate_x64nomem_operand" "=Q,?R,m")
2705         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q,Q")
2706                          (const_int 8)
2707                          (const_int 8)))]
2708   ""
2709 {
2710   switch (get_attr_type (insn))
2711     {
2712     case TYPE_IMOVX:
2713       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2714     default:
2715       return "mov{b}\t{%h1, %0|%0, %h1}";
2716     }
2717 }
2718   [(set_attr "isa" "*,*,nox64")
2719    (set (attr "type")
2720      (if_then_else (and (match_operand:QI 0 "register_operand")
2721                         (ior (not (match_operand:QI 0 "QIreg_operand"))
2722                              (match_test "TARGET_MOVX")))
2723         (const_string "imovx")
2724         (const_string "imov")))
2725    (set (attr "mode")
2726      (if_then_else (eq_attr "type" "imovx")
2727         (const_string "SI")
2728         (const_string "QI")))])
2729
2730 (define_insn "*mov<mode>_extzv_1"
2731   [(set (match_operand:SWI48 0 "register_operand" "=R")
2732         (zero_extract:SWI48 (match_operand 1 "ext_register_operand" "Q")
2733                             (const_int 8)
2734                             (const_int 8)))]
2735   ""
2736   "movz{bl|x}\t{%h1, %k0|%k0, %h1}"
2737   [(set_attr "type" "imovx")
2738    (set_attr "mode" "SI")])
2739
2740 (define_insn "*movqi_extzv_2"
2741   [(set (match_operand:QI 0 "nonimmediate_x64nomem_operand" "=Q,?R,m")
2742         (subreg:QI
2743           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q,Q")
2744                            (const_int 8)
2745                            (const_int 8)) 0))]
2746   ""
2747 {
2748   switch (get_attr_type (insn))
2749     {
2750     case TYPE_IMOVX:
2751       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2752     default:
2753       return "mov{b}\t{%h1, %0|%0, %h1}";
2754     }
2755 }
2756   [(set_attr "isa" "*,*,nox64")
2757    (set (attr "type")
2758      (if_then_else (and (match_operand:QI 0 "register_operand")
2759                         (ior (not (match_operand:QI 0 "QIreg_operand"))
2760                              (match_test "TARGET_MOVX")))
2761         (const_string "imovx")
2762         (const_string "imov")))
2763    (set (attr "mode")
2764      (if_then_else (eq_attr "type" "imovx")
2765         (const_string "SI")
2766         (const_string "QI")))])
2767
2768 (define_insn "mov<mode>_insv_1"
2769   [(set (zero_extract:SWI48 (match_operand 0 "ext_register_operand" "+Q,Q")
2770                              (const_int 8)
2771                              (const_int 8))
2772         (match_operand:SWI48 1 "general_x64nomem_operand" "Qn,m"))]
2773   ""
2774 {
2775   if (CONST_INT_P (operands[1]))
2776     operands[1] = simplify_gen_subreg (QImode, operands[1], <MODE>mode, 0);
2777   return "mov{b}\t{%b1, %h0|%h0, %b1}";
2778 }
2779   [(set_attr "isa" "*,nox64")
2780    (set_attr "type" "imov")
2781    (set_attr "mode" "QI")])
2782
2783 (define_insn "*movqi_insv_2"
2784   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2785                          (const_int 8)
2786                          (const_int 8))
2787         (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
2788                      (const_int 8)))]
2789   ""
2790   "mov{b}\t{%h1, %h0|%h0, %h1}"
2791   [(set_attr "type" "imov")
2792    (set_attr "mode" "QI")])
2793 \f
2794 ;; Floating point push instructions.
2795
2796 (define_insn "*pushtf"
2797   [(set (match_operand:TF 0 "push_operand" "=<,<")
2798         (match_operand:TF 1 "general_no_elim_operand" "x,*roF"))]
2799   "TARGET_64BIT || TARGET_SSE"
2800 {
2801   /* This insn should be already split before reg-stack.  */
2802   gcc_unreachable ();
2803 }
2804   [(set_attr "isa" "*,x64")
2805    (set_attr "type" "multi")
2806    (set_attr "unit" "sse,*")
2807    (set_attr "mode" "TF,DI")])
2808
2809 ;; %%% Kill this when call knows how to work this out.
2810 (define_split
2811   [(set (match_operand:TF 0 "push_operand")
2812         (match_operand:TF 1 "sse_reg_operand"))]
2813   "TARGET_SSE && reload_completed"
2814   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
2815    (set (match_dup 0) (match_dup 1))]
2816 {
2817   /* Preserve memory attributes. */
2818   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2819 })
2820
2821 (define_insn "*pushxf"
2822   [(set (match_operand:XF 0 "push_operand" "=<,<,<,<")
2823         (match_operand:XF 1 "general_no_elim_operand" "f,r,*r,oF"))]
2824   ""
2825 {
2826   /* This insn should be already split before reg-stack.  */
2827   gcc_unreachable ();
2828 }
2829   [(set_attr "type" "multi")
2830    (set_attr "unit" "i387,*,*,*")
2831    (set (attr "mode")
2832         (cond [(eq_attr "alternative" "1,2,3")
2833                  (if_then_else (match_test "TARGET_64BIT")
2834                    (const_string "DI")
2835                    (const_string "SI"))
2836               ]
2837               (const_string "XF")))
2838    (set (attr "preferred_for_size")
2839      (cond [(eq_attr "alternative" "1")
2840               (symbol_ref "false")]
2841            (symbol_ref "true")))])
2842
2843 ;; %%% Kill this when call knows how to work this out.
2844 (define_split
2845   [(set (match_operand:XF 0 "push_operand")
2846         (match_operand:XF 1 "fp_register_operand"))]
2847   "reload_completed"
2848   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2849    (set (match_dup 0) (match_dup 1))]
2850 {
2851   operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));
2852   /* Preserve memory attributes. */
2853   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2854 })
2855
2856 (define_insn "*pushdf"
2857   [(set (match_operand:DF 0 "push_operand" "=<,<,<,<,<,<")
2858         (match_operand:DF 1 "general_no_elim_operand" "f,r,*r,oF,rmF,x"))]
2859   ""
2860 {
2861   /* This insn should be already split before reg-stack.  */
2862   gcc_unreachable ();
2863 }
2864   [(set_attr "isa" "*,nox64,nox64,nox64,x64,sse2")
2865    (set_attr "type" "multi")
2866    (set_attr "unit" "i387,*,*,*,*,sse")
2867    (set_attr "mode" "DF,SI,SI,SI,DI,DF")
2868    (set (attr "preferred_for_size")
2869      (cond [(eq_attr "alternative" "1")
2870               (symbol_ref "false")]
2871            (symbol_ref "true")))
2872    (set (attr "preferred_for_speed")
2873      (cond [(eq_attr "alternative" "1")
2874               (symbol_ref "TARGET_INTEGER_DFMODE_MOVES")]
2875            (symbol_ref "true")))])
2876    
2877 ;; %%% Kill this when call knows how to work this out.
2878 (define_split
2879   [(set (match_operand:DF 0 "push_operand")
2880         (match_operand:DF 1 "any_fp_register_operand"))]
2881   "reload_completed"
2882   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
2883    (set (match_dup 0) (match_dup 1))]
2884 {
2885   /* Preserve memory attributes. */
2886   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2887 })
2888
2889 (define_insn "*pushsf_rex64"
2890   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
2891         (match_operand:SF 1 "nonmemory_no_elim_operand" "f,rF,x"))]
2892   "TARGET_64BIT"
2893 {
2894   /* Anything else should be already split before reg-stack.  */
2895   gcc_assert (which_alternative == 1);
2896   return "push{q}\t%q1";
2897 }
2898   [(set_attr "type" "multi,push,multi")
2899    (set_attr "unit" "i387,*,*")
2900    (set_attr "mode" "SF,DI,SF")])
2901
2902 (define_insn "*pushsf"
2903   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
2904         (match_operand:SF 1 "general_no_elim_operand" "f,rmF,x"))]
2905   "!TARGET_64BIT"
2906 {
2907   /* Anything else should be already split before reg-stack.  */
2908   gcc_assert (which_alternative == 1);
2909   return "push{l}\t%1";
2910 }
2911   [(set_attr "type" "multi,push,multi")
2912    (set_attr "unit" "i387,*,*")
2913    (set_attr "mode" "SF,SI,SF")])
2914
2915 ;; %%% Kill this when call knows how to work this out.
2916 (define_split
2917   [(set (match_operand:SF 0 "push_operand")
2918         (match_operand:SF 1 "any_fp_register_operand"))]
2919   "reload_completed"
2920   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2921    (set (match_dup 0) (match_dup 1))]
2922 {
2923   rtx op = XEXP (operands[0], 0);
2924   if (GET_CODE (op) == PRE_DEC)
2925     {
2926       gcc_assert (!TARGET_64BIT);
2927       op = GEN_INT (-4);
2928     }
2929   else
2930     {
2931       op = XEXP (XEXP (op, 1), 1);
2932       gcc_assert (CONST_INT_P (op));
2933     }
2934   operands[2] = op;
2935   /* Preserve memory attributes. */
2936   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2937 })
2938
2939 (define_split
2940   [(set (match_operand:SF 0 "push_operand")
2941         (match_operand:SF 1 "memory_operand"))]
2942   "reload_completed
2943    && (operands[2] = find_constant_src (insn))"
2944   [(set (match_dup 0) (match_dup 2))])
2945
2946 (define_split
2947   [(set (match_operand 0 "push_operand")
2948         (match_operand 1 "general_operand"))]
2949   "reload_completed
2950    && (GET_MODE (operands[0]) == TFmode
2951        || GET_MODE (operands[0]) == XFmode
2952        || GET_MODE (operands[0]) == DFmode)
2953    && !ANY_FP_REG_P (operands[1])"
2954   [(const_int 0)]
2955   "ix86_split_long_move (operands); DONE;")
2956 \f
2957 ;; Floating point move instructions.
2958
2959 (define_expand "movtf"
2960   [(set (match_operand:TF 0 "nonimmediate_operand")
2961         (match_operand:TF 1 "nonimmediate_operand"))]
2962   "TARGET_64BIT || TARGET_SSE"
2963   "ix86_expand_move (TFmode, operands); DONE;")
2964
2965 (define_expand "mov<mode>"
2966   [(set (match_operand:X87MODEF 0 "nonimmediate_operand")
2967         (match_operand:X87MODEF 1 "general_operand"))]
2968   ""
2969   "ix86_expand_move (<MODE>mode, operands); DONE;")
2970
2971 (define_insn "*movtf_internal"
2972   [(set (match_operand:TF 0 "nonimmediate_operand" "=x,x ,m,?*r ,!o")
2973         (match_operand:TF 1 "general_operand"      "C ,xm,x,*roF,*rC"))]
2974   "(TARGET_64BIT || TARGET_SSE)
2975    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2976    && (!can_create_pseudo_p ()
2977        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2978        || GET_CODE (operands[1]) != CONST_DOUBLE
2979        || (optimize_function_for_size_p (cfun)
2980            && standard_sse_constant_p (operands[1])
2981            && !memory_operand (operands[0], TFmode))
2982        || (!TARGET_MEMORY_MISMATCH_STALL
2983            && memory_operand (operands[0], TFmode)))"
2984 {
2985   switch (get_attr_type (insn))
2986     {
2987     case TYPE_SSELOG1:
2988       return standard_sse_constant_opcode (insn, operands[1]);
2989
2990     case TYPE_SSEMOV:
2991       /* Handle misaligned load/store since we
2992          don't have movmisaligntf pattern. */
2993       if (misaligned_operand (operands[0], TFmode)
2994           || misaligned_operand (operands[1], TFmode))
2995         {
2996           if (get_attr_mode (insn) == MODE_V4SF)
2997             return "%vmovups\t{%1, %0|%0, %1}";
2998           else
2999             return "%vmovdqu\t{%1, %0|%0, %1}";
3000         }
3001       else
3002         {
3003           if (get_attr_mode (insn) == MODE_V4SF)
3004             return "%vmovaps\t{%1, %0|%0, %1}";
3005           else
3006             return "%vmovdqa\t{%1, %0|%0, %1}";
3007         }
3008
3009     case TYPE_MULTI:
3010         return "#";
3011
3012     default:
3013       gcc_unreachable ();
3014     }
3015 }
3016   [(set_attr "isa" "*,*,*,x64,x64")
3017    (set_attr "type" "sselog1,ssemov,ssemov,multi,multi")
3018    (set (attr "prefix")
3019      (if_then_else (eq_attr "type" "sselog1,ssemov")
3020        (const_string "maybe_vex")
3021        (const_string "orig")))
3022    (set (attr "mode")
3023         (cond [(eq_attr "alternative" "3,4")
3024                  (const_string "DI")
3025                (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
3026                  (const_string "V4SF")
3027                (and (eq_attr "alternative" "2")
3028                     (match_test "TARGET_SSE_TYPELESS_STORES"))
3029                  (const_string "V4SF")
3030                (match_test "TARGET_AVX")
3031                  (const_string "TI")
3032                (ior (not (match_test "TARGET_SSE2"))
3033                     (match_test "optimize_function_for_size_p (cfun)"))
3034                  (const_string "V4SF")
3035                ]
3036                (const_string "TI")))])
3037
3038 ;; Possible store forwarding (partial memory) stall
3039 ;; in alternatives 4, 6, 7 and 8.
3040 (define_insn "*movxf_internal"
3041   [(set (match_operand:XF 0 "nonimmediate_operand"
3042          "=f,m,f,?r ,!o,?*r ,!o,!o,!o")
3043         (match_operand:XF 1 "general_operand"
3044          "fm,f,G,roF,r , *roF,*r,F ,C"))]
3045   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3046    && (!can_create_pseudo_p ()
3047        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3048        || GET_CODE (operands[1]) != CONST_DOUBLE
3049        || (optimize_function_for_size_p (cfun)
3050            && standard_80387_constant_p (operands[1]) > 0
3051            && !memory_operand (operands[0], XFmode))
3052        || (!TARGET_MEMORY_MISMATCH_STALL
3053            && memory_operand (operands[0], XFmode)))"
3054 {
3055   switch (get_attr_type (insn))
3056     {
3057     case TYPE_FMOV:
3058       if (which_alternative == 2)
3059         return standard_80387_constant_opcode (operands[1]);
3060       return output_387_reg_move (insn, operands);
3061
3062     case TYPE_MULTI:
3063       return "#";
3064
3065     default:
3066       gcc_unreachable ();
3067     }
3068 }
3069   [(set (attr "isa")
3070         (cond [(eq_attr "alternative" "7")
3071                  (const_string "nox64")
3072                (eq_attr "alternative" "8")
3073                  (const_string "x64")
3074               ]
3075               (const_string "*")))
3076    (set (attr "type")
3077         (cond [(eq_attr "alternative" "3,4,5,6,7,8")
3078                  (const_string "multi")
3079               ]
3080               (const_string "fmov")))
3081    (set (attr "mode")
3082         (cond [(eq_attr "alternative" "3,4,5,6,7,8")
3083                  (if_then_else (match_test "TARGET_64BIT")
3084                    (const_string "DI")
3085                    (const_string "SI"))
3086               ]
3087               (const_string "XF")))
3088    (set (attr "preferred_for_size")
3089      (cond [(eq_attr "alternative" "3,4")
3090               (symbol_ref "false")]
3091            (symbol_ref "true")))])
3092    
3093 ;; Possible store forwarding (partial memory) stall in alternatives 4, 6 and 7.
3094 (define_insn "*movdf_internal"
3095   [(set (match_operand:DF 0 "nonimmediate_operand"
3096     "=Yf*f,m   ,Yf*f,?r ,!o,?*r ,!o,!o,?r,?m,?r,?r,v,v,v,m,*x,*x,*x,m ,r ,Yi")
3097         (match_operand:DF 1 "general_operand"
3098     "Yf*fm,Yf*f,G   ,roF,r ,*roF,*r,F ,rm,rC,C ,F ,C,v,m,v,C ,*x,m ,*x,Yj,r"))]
3099   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3100    && (!can_create_pseudo_p ()
3101        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3102        || GET_CODE (operands[1]) != CONST_DOUBLE
3103        || (optimize_function_for_size_p (cfun)
3104            && ((!(TARGET_SSE2 && TARGET_SSE_MATH)
3105                 && standard_80387_constant_p (operands[1]) > 0)
3106                || (TARGET_SSE2 && TARGET_SSE_MATH
3107                    && standard_sse_constant_p (operands[1])))
3108            && !memory_operand (operands[0], DFmode))
3109        || ((TARGET_64BIT || !TARGET_MEMORY_MISMATCH_STALL)
3110            && memory_operand (operands[0], DFmode)))"
3111 {
3112   switch (get_attr_type (insn))
3113     {
3114     case TYPE_FMOV:
3115       if (which_alternative == 2)
3116         return standard_80387_constant_opcode (operands[1]);
3117       return output_387_reg_move (insn, operands);
3118
3119     case TYPE_MULTI:
3120       return "#";
3121
3122     case TYPE_IMOV:
3123       if (get_attr_mode (insn) == MODE_SI)
3124         return "mov{l}\t{%1, %k0|%k0, %1}";
3125       else if (which_alternative == 11)
3126         return "movabs{q}\t{%1, %0|%0, %1}";
3127       else
3128         return "mov{q}\t{%1, %0|%0, %1}";
3129
3130     case TYPE_SSELOG1:
3131       return standard_sse_constant_opcode (insn, operands[1]);
3132
3133     case TYPE_SSEMOV:
3134       switch (get_attr_mode (insn))
3135         {
3136         case MODE_DF:
3137           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3138             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3139           return "%vmovsd\t{%1, %0|%0, %1}";
3140
3141         case MODE_V4SF:
3142           return "%vmovaps\t{%1, %0|%0, %1}";
3143         case MODE_V8DF:
3144           return "vmovapd\t{%g1, %g0|%g0, %g1}";
3145         case MODE_V2DF:
3146           return "%vmovapd\t{%1, %0|%0, %1}";
3147
3148         case MODE_V2SF:
3149           gcc_assert (!TARGET_AVX);
3150           return "movlps\t{%1, %0|%0, %1}";
3151         case MODE_V1DF:
3152           gcc_assert (!TARGET_AVX);
3153           return "movlpd\t{%1, %0|%0, %1}";
3154
3155         case MODE_DI:
3156           /* Handle broken assemblers that require movd instead of movq.  */
3157           if (!HAVE_AS_IX86_INTERUNIT_MOVQ
3158               && (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1])))
3159             return "%vmovd\t{%1, %0|%0, %1}";
3160           return "%vmovq\t{%1, %0|%0, %1}";
3161
3162         default:
3163           gcc_unreachable ();
3164         }
3165
3166     default:
3167       gcc_unreachable ();
3168     }
3169 }
3170   [(set (attr "isa")
3171         (cond [(eq_attr "alternative" "3,4,5,6,7")
3172                  (const_string "nox64")
3173                (eq_attr "alternative" "8,9,10,11,20,21")
3174                  (const_string "x64")
3175                (eq_attr "alternative" "12,13,14,15")
3176                  (const_string "sse2")
3177               ]
3178               (const_string "*")))
3179    (set (attr "type")
3180         (cond [(eq_attr "alternative" "0,1,2")
3181                  (const_string "fmov")
3182                (eq_attr "alternative" "3,4,5,6,7")
3183                  (const_string "multi")
3184                (eq_attr "alternative" "8,9,10,11")
3185                  (const_string "imov")
3186                (eq_attr "alternative" "12,16")
3187                  (const_string "sselog1")
3188               ]
3189               (const_string "ssemov")))
3190    (set (attr "modrm")
3191      (if_then_else (eq_attr "alternative" "11")
3192        (const_string "0")
3193        (const_string "*")))
3194    (set (attr "length_immediate")
3195      (if_then_else (eq_attr "alternative" "11")
3196        (const_string "8")
3197        (const_string "*")))
3198    (set (attr "prefix")
3199      (if_then_else (eq_attr "type" "sselog1,ssemov")
3200        (const_string "maybe_vex")
3201        (const_string "orig")))
3202    (set (attr "prefix_data16")
3203      (if_then_else
3204        (ior (and (eq_attr "type" "ssemov") (eq_attr "mode" "DI"))
3205             (eq_attr "mode" "V1DF"))
3206        (const_string "1")
3207        (const_string "*")))
3208    (set (attr "mode")
3209         (cond [(eq_attr "alternative" "3,4,5,6,7,10")
3210                  (const_string "SI")
3211                (eq_attr "alternative" "8,9,11,20,21")
3212                  (const_string "DI")
3213
3214                /* xorps is one byte shorter for non-AVX targets.  */
3215                (eq_attr "alternative" "12,16")
3216                  (cond [(not (match_test "TARGET_SSE2"))
3217                           (const_string "V4SF")
3218                         (match_test "TARGET_AVX512F")
3219                           (const_string "XI")
3220                         (match_test "TARGET_AVX")
3221                           (const_string "V2DF")
3222                         (match_test "optimize_function_for_size_p (cfun)")
3223                           (const_string "V4SF")
3224                         (match_test "TARGET_SSE_LOAD0_BY_PXOR")
3225                           (const_string "TI")
3226                        ]
3227                        (const_string "V2DF"))
3228
3229                /* For architectures resolving dependencies on
3230                   whole SSE registers use movapd to break dependency
3231                   chains, otherwise use short move to avoid extra work.  */
3232
3233                /* movaps is one byte shorter for non-AVX targets.  */
3234                (eq_attr "alternative" "13,17")
3235                  (cond [(ior (match_operand 0 "ext_sse_reg_operand")
3236                              (match_operand 1 "ext_sse_reg_operand"))
3237                           (const_string "V8DF")
3238                         (ior (not (match_test "TARGET_SSE2"))
3239                              (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
3240                           (const_string "V4SF")
3241                         (match_test "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3242                           (const_string "V2DF")
3243                         (match_test "TARGET_AVX")
3244                           (const_string "DF")
3245                         (match_test "optimize_function_for_size_p (cfun)")
3246                           (const_string "V4SF")
3247                        ]
3248                        (const_string "DF"))
3249
3250                /* For architectures resolving dependencies on register
3251                   parts we may avoid extra work to zero out upper part
3252                   of register.  */
3253                (eq_attr "alternative" "14,18")
3254                  (cond [(not (match_test "TARGET_SSE2"))
3255                           (const_string "V2SF")
3256                         (match_test "TARGET_AVX")
3257                           (const_string "DF")
3258                         (match_test "TARGET_SSE_SPLIT_REGS")
3259                           (const_string "V1DF")
3260                        ]
3261                        (const_string "DF"))
3262
3263                (and (eq_attr "alternative" "15,19")
3264                     (not (match_test "TARGET_SSE2")))
3265                  (const_string "V2SF")
3266               ]
3267               (const_string "DF")))
3268    (set (attr "preferred_for_size")
3269      (cond [(eq_attr "alternative" "3,4")
3270               (symbol_ref "false")]
3271            (symbol_ref "true")))
3272    (set (attr "preferred_for_speed")
3273      (cond [(eq_attr "alternative" "3,4")
3274               (symbol_ref "TARGET_INTEGER_DFMODE_MOVES")]
3275            (symbol_ref "true")))])
3276
3277 (define_insn "*movsf_internal"
3278   [(set (match_operand:SF 0 "nonimmediate_operand"
3279           "=Yf*f,m   ,Yf*f,?r ,?m,v,v,v,m,?r,?Yi,!*y,!*y,!m,!r ,!*Ym")
3280         (match_operand:SF 1 "general_operand"
3281           "Yf*fm,Yf*f,G   ,rmF,rF,C,v,m,v,Yj,r  ,*y ,m  ,*y,*Yn,r"))]
3282   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3283    && (!can_create_pseudo_p ()
3284        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3285        || GET_CODE (operands[1]) != CONST_DOUBLE
3286        || (optimize_function_for_size_p (cfun)
3287            && ((!TARGET_SSE_MATH
3288                 && standard_80387_constant_p (operands[1]) > 0)
3289                || (TARGET_SSE_MATH
3290                    && standard_sse_constant_p (operands[1]))))
3291        || memory_operand (operands[0], SFmode))"
3292 {
3293   switch (get_attr_type (insn))
3294     {
3295     case TYPE_FMOV:
3296       if (which_alternative == 2)
3297         return standard_80387_constant_opcode (operands[1]);
3298       return output_387_reg_move (insn, operands);
3299
3300     case TYPE_IMOV:
3301       return "mov{l}\t{%1, %0|%0, %1}";
3302
3303     case TYPE_SSELOG1:
3304       return standard_sse_constant_opcode (insn, operands[1]);
3305
3306     case TYPE_SSEMOV:
3307       switch (get_attr_mode (insn))
3308         {
3309         case MODE_SF:
3310           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3311             return "vmovss\t{%1, %0, %0|%0, %0, %1}";
3312           return "%vmovss\t{%1, %0|%0, %1}";
3313
3314         case MODE_V16SF:
3315           return "vmovaps\t{%g1, %g0|%g0, %g1}";
3316         case MODE_V4SF:
3317           return "%vmovaps\t{%1, %0|%0, %1}";
3318
3319         case MODE_SI:
3320           return "%vmovd\t{%1, %0|%0, %1}";
3321
3322         default:
3323           gcc_unreachable ();
3324         }
3325
3326     case TYPE_MMXMOV:
3327       switch (get_attr_mode (insn))
3328         {
3329         case MODE_DI:
3330           return "movq\t{%1, %0|%0, %1}";
3331         case MODE_SI:
3332           return "movd\t{%1, %0|%0, %1}";
3333
3334         default:
3335           gcc_unreachable ();
3336         }
3337
3338     default:
3339       gcc_unreachable ();
3340     }
3341 }
3342   [(set (attr "type")
3343         (cond [(eq_attr "alternative" "0,1,2")
3344                  (const_string "fmov")
3345                (eq_attr "alternative" "3,4")
3346                  (const_string "imov")
3347                (eq_attr "alternative" "5")
3348                  (const_string "sselog1")
3349                (eq_attr "alternative" "11,12,13,14,15")
3350                  (const_string "mmxmov")
3351               ]
3352               (const_string "ssemov")))
3353    (set (attr "prefix")
3354      (if_then_else (eq_attr "type" "sselog1,ssemov")
3355        (const_string "maybe_vex")
3356        (const_string "orig")))
3357    (set (attr "prefix_data16")
3358      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
3359        (const_string "1")
3360        (const_string "*")))
3361    (set (attr "mode")
3362         (cond [(eq_attr "alternative" "3,4,9,10,12,13,14,15")
3363                  (const_string "SI")
3364                (eq_attr "alternative" "11")
3365                  (const_string "DI")
3366                (eq_attr "alternative" "5")
3367                  (cond [(not (match_test "TARGET_SSE2"))
3368                           (const_string "V4SF")
3369                         (match_test "TARGET_AVX512F")
3370                           (const_string "V16SF")
3371                         (match_test "TARGET_AVX")
3372                           (const_string "V4SF")
3373                         (match_test "optimize_function_for_size_p (cfun)")
3374                           (const_string "V4SF")
3375                         (match_test "TARGET_SSE_LOAD0_BY_PXOR")
3376                           (const_string "TI")
3377                        ]
3378                        (const_string "V4SF"))
3379
3380                /* For architectures resolving dependencies on
3381                   whole SSE registers use APS move to break dependency
3382                   chains, otherwise use short move to avoid extra work.
3383
3384                   Do the same for architectures resolving dependencies on
3385                   the parts.  While in DF mode it is better to always handle
3386                   just register parts, the SF mode is different due to lack
3387                   of instructions to load just part of the register.  It is
3388                   better to maintain the whole registers in single format
3389                   to avoid problems on using packed logical operations.  */
3390                (eq_attr "alternative" "6")
3391                  (cond [(ior  (match_operand 0 "ext_sse_reg_operand")
3392                               (match_operand 1 "ext_sse_reg_operand"))
3393                           (const_string "V16SF")
3394                         (ior (match_test "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3395                              (match_test "TARGET_SSE_SPLIT_REGS"))
3396                           (const_string "V4SF")
3397                        ]
3398                        (const_string "SF"))
3399               ]
3400               (const_string "SF")))])
3401
3402 (define_split
3403   [(set (match_operand 0 "any_fp_register_operand")
3404         (match_operand 1 "memory_operand"))]
3405   "reload_completed
3406    && (GET_MODE (operands[0]) == TFmode
3407        || GET_MODE (operands[0]) == XFmode
3408        || GET_MODE (operands[0]) == DFmode
3409        || GET_MODE (operands[0]) == SFmode)
3410    && (operands[2] = find_constant_src (insn))"
3411   [(set (match_dup 0) (match_dup 2))]
3412 {
3413   rtx c = operands[2];
3414   int r = REGNO (operands[0]);
3415
3416   if ((SSE_REGNO_P (r) && !standard_sse_constant_p (c))
3417       || (STACK_REGNO_P (r) && standard_80387_constant_p (c) < 1))
3418     FAIL;
3419 })
3420
3421 (define_split
3422   [(set (match_operand 0 "any_fp_register_operand")
3423         (float_extend (match_operand 1 "memory_operand")))]
3424   "reload_completed
3425    && (GET_MODE (operands[0]) == TFmode
3426        || GET_MODE (operands[0]) == XFmode
3427        || GET_MODE (operands[0]) == DFmode)
3428    && (operands[2] = find_constant_src (insn))"
3429   [(set (match_dup 0) (match_dup 2))]
3430 {
3431   rtx c = operands[2];
3432   int r = REGNO (operands[0]);
3433
3434   if ((SSE_REGNO_P (r) && !standard_sse_constant_p (c))
3435       || (STACK_REGNO_P (r) && standard_80387_constant_p (c) < 1))
3436     FAIL;
3437 })
3438
3439 ;; Split the load of -0.0 or -1.0 into fldz;fchs or fld1;fchs sequence
3440 (define_split
3441   [(set (match_operand:X87MODEF 0 "fp_register_operand")
3442         (match_operand:X87MODEF 1 "immediate_operand"))]
3443   "reload_completed
3444    && (standard_80387_constant_p (operands[1]) == 8
3445        || standard_80387_constant_p (operands[1]) == 9)"
3446   [(set (match_dup 0)(match_dup 1))
3447    (set (match_dup 0)
3448         (neg:X87MODEF (match_dup 0)))]
3449 {
3450   REAL_VALUE_TYPE r;
3451
3452   REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
3453   if (real_isnegzero (&r))
3454     operands[1] = CONST0_RTX (<MODE>mode);
3455   else
3456     operands[1] = CONST1_RTX (<MODE>mode);
3457 })
3458
3459 (define_split
3460   [(set (match_operand 0 "nonimmediate_operand")
3461         (match_operand 1 "general_operand"))]
3462   "reload_completed
3463    && (GET_MODE (operands[0]) == TFmode
3464        || GET_MODE (operands[0]) == XFmode
3465        || GET_MODE (operands[0]) == DFmode)
3466    && !(ANY_FP_REG_P (operands[0]) || ANY_FP_REG_P (operands[1]))"
3467   [(const_int 0)]
3468   "ix86_split_long_move (operands); DONE;")
3469
3470 (define_insn "swapxf"
3471   [(set (match_operand:XF 0 "register_operand" "+f")
3472         (match_operand:XF 1 "register_operand" "+f"))
3473    (set (match_dup 1)
3474         (match_dup 0))]
3475   "TARGET_80387"
3476 {
3477   if (STACK_TOP_P (operands[0]))
3478     return "fxch\t%1";
3479   else
3480     return "fxch\t%0";
3481 }
3482   [(set_attr "type" "fxch")
3483    (set_attr "mode" "XF")])
3484
3485 (define_insn "*swap<mode>"
3486   [(set (match_operand:MODEF 0 "fp_register_operand" "+f")
3487         (match_operand:MODEF 1 "fp_register_operand" "+f"))
3488    (set (match_dup 1)
3489         (match_dup 0))]
3490   "TARGET_80387 || reload_completed"
3491 {
3492   if (STACK_TOP_P (operands[0]))
3493     return "fxch\t%1";
3494   else
3495     return "fxch\t%0";
3496 }
3497   [(set_attr "type" "fxch")
3498    (set_attr "mode" "<MODE>")])
3499 \f
3500 ;; Zero extension instructions
3501
3502 (define_expand "zero_extendsidi2"
3503   [(set (match_operand:DI 0 "nonimmediate_operand")
3504         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))])
3505
3506 (define_insn "*zero_extendsidi2"
3507   [(set (match_operand:DI 0 "nonimmediate_operand"
3508                         "=r,?r,?o,r   ,o,?*Ym,?!*y,?r ,?r,?*Yi,?*x")
3509         (zero_extend:DI
3510          (match_operand:SI 1 "x86_64_zext_operand"
3511                         "0 ,rm,r ,rmWz,0,r   ,m   ,*Yj,*x,r   ,m")))]
3512   ""
3513 {
3514   switch (get_attr_type (insn))
3515     {
3516     case TYPE_IMOVX:
3517       if (ix86_use_lea_for_mov (insn, operands))
3518         return "lea{l}\t{%E1, %k0|%k0, %E1}";
3519       else
3520         return "mov{l}\t{%1, %k0|%k0, %1}";
3521
3522     case TYPE_MULTI:
3523       return "#";
3524
3525     case TYPE_MMXMOV:
3526       return "movd\t{%1, %0|%0, %1}";
3527
3528     case TYPE_SSELOG1:
3529       return "%vpextrd\t{$0, %1, %k0|%k0, %1, 0}";
3530
3531     case TYPE_SSEMOV:
3532       if (GENERAL_REG_P (operands[0]))
3533         return "%vmovd\t{%1, %k0|%k0, %1}";
3534
3535       return "%vmovd\t{%1, %0|%0, %1}";
3536
3537     default:
3538       gcc_unreachable ();
3539     }
3540 }
3541   [(set (attr "isa")
3542      (cond [(eq_attr "alternative" "0,1,2")
3543               (const_string "nox64")
3544             (eq_attr "alternative" "3,7")
3545               (const_string "x64")
3546             (eq_attr "alternative" "8")
3547               (const_string "x64_sse4")
3548             (eq_attr "alternative" "10")
3549               (const_string "sse2")
3550            ]
3551            (const_string "*")))
3552    (set (attr "type")
3553      (cond [(eq_attr "alternative" "0,1,2,4")
3554               (const_string "multi")
3555             (eq_attr "alternative" "5,6")
3556               (const_string "mmxmov")
3557             (eq_attr "alternative" "7,9,10")
3558               (const_string "ssemov")
3559             (eq_attr "alternative" "8")
3560               (const_string "sselog1")
3561            ]
3562            (const_string "imovx")))
3563    (set (attr "prefix_extra")
3564      (if_then_else (eq_attr "alternative" "8")
3565        (const_string "1")
3566        (const_string "*")))
3567    (set (attr "length_immediate")
3568      (if_then_else (eq_attr "alternative" "8")
3569        (const_string "1")
3570        (const_string "*")))
3571    (set (attr "prefix")
3572      (if_then_else (eq_attr "type" "ssemov,sselog1")
3573        (const_string "maybe_vex")
3574        (const_string "orig")))
3575    (set (attr "prefix_0f")
3576      (if_then_else (eq_attr "type" "imovx")
3577        (const_string "0")
3578        (const_string "*")))
3579    (set (attr "mode")
3580      (cond [(eq_attr "alternative" "5,6")
3581               (const_string "DI")
3582             (eq_attr "alternative" "7,8,9")
3583               (const_string "TI")
3584            ]
3585            (const_string "SI")))])
3586
3587 (define_split
3588   [(set (match_operand:DI 0 "memory_operand")
3589         (zero_extend:DI (match_operand:SI 1 "memory_operand")))]
3590   "reload_completed"
3591   [(set (match_dup 4) (const_int 0))]
3592   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3593
3594 (define_split
3595   [(set (match_operand:DI 0 "register_operand")
3596         (zero_extend:DI (match_operand:SI 1 "register_operand")))]
3597   "!TARGET_64BIT && reload_completed
3598    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))
3599    && true_regnum (operands[0]) == true_regnum (operands[1])"
3600   [(set (match_dup 4) (const_int 0))]
3601   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3602
3603 (define_split
3604   [(set (match_operand:DI 0 "nonimmediate_operand")
3605         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3606   "!TARGET_64BIT && reload_completed
3607    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3608    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))"
3609   [(set (match_dup 3) (match_dup 1))
3610    (set (match_dup 4) (const_int 0))]
3611   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3612
3613 (define_insn "zero_extend<mode>di2"
3614   [(set (match_operand:DI 0 "register_operand" "=r")
3615         (zero_extend:DI
3616          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3617   "TARGET_64BIT"
3618   "movz{<imodesuffix>l|x}\t{%1, %k0|%k0, %1}"
3619   [(set_attr "type" "imovx")
3620    (set_attr "mode" "SI")])
3621
3622 (define_expand "zero_extend<mode>si2"
3623   [(set (match_operand:SI 0 "register_operand")
3624         (zero_extend:SI (match_operand:SWI12 1 "nonimmediate_operand")))]
3625   ""
3626 {
3627   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3628     {
3629       operands[1] = force_reg (<MODE>mode, operands[1]);
3630       emit_insn (gen_zero_extend<mode>si2_and (operands[0], operands[1]));
3631       DONE;
3632     }
3633 })
3634
3635 (define_insn_and_split "zero_extend<mode>si2_and"
3636   [(set (match_operand:SI 0 "register_operand" "=r,?&<r>")
3637         (zero_extend:SI
3638           (match_operand:SWI12 1 "nonimmediate_operand" "0,<r>m")))
3639    (clobber (reg:CC FLAGS_REG))]
3640   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3641   "#"
3642   "&& reload_completed"
3643   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 2)))
3644               (clobber (reg:CC FLAGS_REG))])]
3645 {
3646   if (true_regnum (operands[0]) != true_regnum (operands[1]))
3647     {
3648       ix86_expand_clear (operands[0]);
3649
3650       gcc_assert (!TARGET_PARTIAL_REG_STALL);
3651       emit_insn (gen_movstrict<mode>
3652                   (gen_lowpart (<MODE>mode, operands[0]), operands[1]));
3653       DONE;
3654     }
3655
3656   operands[2] = GEN_INT (GET_MODE_MASK (<MODE>mode));
3657 }
3658   [(set_attr "type" "alu1")
3659    (set_attr "mode" "SI")])
3660
3661 (define_insn "*zero_extend<mode>si2"
3662   [(set (match_operand:SI 0 "register_operand" "=r")
3663         (zero_extend:SI
3664           (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3665   "!(TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))"
3666   "movz{<imodesuffix>l|x}\t{%1, %0|%0, %1}"
3667   [(set_attr "type" "imovx")
3668    (set_attr "mode" "SI")])
3669
3670 (define_expand "zero_extendqihi2"
3671   [(set (match_operand:HI 0 "register_operand")
3672         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3673   ""
3674 {
3675   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3676     {
3677       operands[1] = force_reg (QImode, operands[1]);
3678       emit_insn (gen_zero_extendqihi2_and (operands[0], operands[1]));
3679       DONE;
3680     }
3681 })
3682
3683 (define_insn_and_split "zero_extendqihi2_and"
3684   [(set (match_operand:HI 0 "register_operand" "=r,?&q")
3685         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3686    (clobber (reg:CC FLAGS_REG))]
3687   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3688   "#"
3689   "&& reload_completed"
3690   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 255)))
3691               (clobber (reg:CC FLAGS_REG))])]
3692 {
3693   if (true_regnum (operands[0]) != true_regnum (operands[1]))
3694     {
3695       ix86_expand_clear (operands[0]);
3696
3697       gcc_assert (!TARGET_PARTIAL_REG_STALL);
3698       emit_insn (gen_movstrictqi
3699                   (gen_lowpart (QImode, operands[0]), operands[1]));
3700       DONE;
3701     }
3702
3703   operands[0] = gen_lowpart (SImode, operands[0]);
3704 }
3705   [(set_attr "type" "alu1")
3706    (set_attr "mode" "SI")])
3707
3708 ; zero extend to SImode to avoid partial register stalls
3709 (define_insn "*zero_extendqihi2"
3710   [(set (match_operand:HI 0 "register_operand" "=r")
3711         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3712   "!(TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))"
3713   "movz{bl|x}\t{%1, %k0|%k0, %1}"
3714   [(set_attr "type" "imovx")
3715    (set_attr "mode" "SI")])
3716 \f
3717 ;; Sign extension instructions
3718
3719 (define_expand "extendsidi2"
3720   [(set (match_operand:DI 0 "register_operand")
3721         (sign_extend:DI (match_operand:SI 1 "register_operand")))]
3722   ""
3723 {
3724   if (!TARGET_64BIT)
3725     {
3726       emit_insn (gen_extendsidi2_1 (operands[0], operands[1]));
3727       DONE;
3728     }
3729 })
3730
3731 (define_insn "*extendsidi2_rex64"
3732   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3733         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
3734   "TARGET_64BIT"
3735   "@
3736    {cltq|cdqe}
3737    movs{lq|x}\t{%1, %0|%0, %1}"
3738   [(set_attr "type" "imovx")
3739    (set_attr "mode" "DI")
3740    (set_attr "prefix_0f" "0")
3741    (set_attr "modrm" "0,1")])
3742
3743 (define_insn "extendsidi2_1"
3744   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
3745         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
3746    (clobber (reg:CC FLAGS_REG))
3747    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
3748   "!TARGET_64BIT"
3749   "#")
3750
3751 ;; Split the memory case.  If the source register doesn't die, it will stay
3752 ;; this way, if it does die, following peephole2s take care of it.
3753 (define_split
3754   [(set (match_operand:DI 0 "memory_operand")
3755         (sign_extend:DI (match_operand:SI 1 "register_operand")))
3756    (clobber (reg:CC FLAGS_REG))
3757    (clobber (match_operand:SI 2 "register_operand"))]
3758   "reload_completed"
3759   [(const_int 0)]
3760 {
3761   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3762
3763   emit_move_insn (operands[3], operands[1]);
3764
3765   /* Generate a cltd if possible and doing so it profitable.  */
3766   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3767       && true_regnum (operands[1]) == AX_REG
3768       && true_regnum (operands[2]) == DX_REG)
3769     {
3770       emit_insn (gen_ashrsi3_cvt (operands[2], operands[1], GEN_INT (31)));
3771     }
3772   else
3773     {
3774       emit_move_insn (operands[2], operands[1]);
3775       emit_insn (gen_ashrsi3_cvt (operands[2], operands[2], GEN_INT (31)));
3776     }
3777   emit_move_insn (operands[4], operands[2]);
3778   DONE;
3779 })
3780
3781 ;; Peepholes for the case where the source register does die, after
3782 ;; being split with the above splitter.
3783 (define_peephole2
3784   [(set (match_operand:SI 0 "memory_operand")
3785         (match_operand:SI 1 "register_operand"))
3786    (set (match_operand:SI 2 "register_operand") (match_dup 1))
3787    (parallel [(set (match_dup 2)
3788                    (ashiftrt:SI (match_dup 2) (const_int 31)))
3789                (clobber (reg:CC FLAGS_REG))])
3790    (set (match_operand:SI 3 "memory_operand") (match_dup 2))]
3791   "REGNO (operands[1]) != REGNO (operands[2])
3792    && peep2_reg_dead_p (2, operands[1])
3793    && peep2_reg_dead_p (4, operands[2])
3794    && !reg_mentioned_p (operands[2], operands[3])"
3795   [(set (match_dup 0) (match_dup 1))
3796    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3797               (clobber (reg:CC FLAGS_REG))])
3798    (set (match_dup 3) (match_dup 1))])
3799
3800 (define_peephole2
3801   [(set (match_operand:SI 0 "memory_operand")
3802         (match_operand:SI 1 "register_operand"))
3803    (parallel [(set (match_operand:SI 2 "register_operand")
3804                    (ashiftrt:SI (match_dup 1) (const_int 31)))
3805                (clobber (reg:CC FLAGS_REG))])
3806    (set (match_operand:SI 3 "memory_operand") (match_dup 2))]
3807   "/* cltd is shorter than sarl $31, %eax */
3808    !optimize_function_for_size_p (cfun)
3809    && true_regnum (operands[1]) == AX_REG
3810    && true_regnum (operands[2]) == DX_REG
3811    && peep2_reg_dead_p (2, operands[1])
3812    && peep2_reg_dead_p (3, operands[2])
3813    && !reg_mentioned_p (operands[2], operands[3])"
3814   [(set (match_dup 0) (match_dup 1))
3815    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3816               (clobber (reg:CC FLAGS_REG))])
3817    (set (match_dup 3) (match_dup 1))])
3818
3819 ;; Extend to register case.  Optimize case where source and destination
3820 ;; registers match and cases where we can use cltd.
3821 (define_split
3822   [(set (match_operand:DI 0 "register_operand")
3823         (sign_extend:DI (match_operand:SI 1 "register_operand")))
3824    (clobber (reg:CC FLAGS_REG))
3825    (clobber (match_scratch:SI 2))]
3826   "reload_completed"
3827   [(const_int 0)]
3828 {
3829   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3830
3831   if (true_regnum (operands[3]) != true_regnum (operands[1]))
3832     emit_move_insn (operands[3], operands[1]);
3833
3834   /* Generate a cltd if possible and doing so it profitable.  */
3835   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3836       && true_regnum (operands[3]) == AX_REG
3837       && true_regnum (operands[4]) == DX_REG)
3838     {
3839       emit_insn (gen_ashrsi3_cvt (operands[4], operands[3], GEN_INT (31)));
3840       DONE;
3841     }
3842
3843   if (true_regnum (operands[4]) != true_regnum (operands[1]))
3844     emit_move_insn (operands[4], operands[1]);
3845
3846   emit_insn (gen_ashrsi3_cvt (operands[4], operands[4], GEN_INT (31)));
3847   DONE;
3848 })
3849
3850 (define_insn "extend<mode>di2"
3851   [(set (match_operand:DI 0 "register_operand" "=r")
3852         (sign_extend:DI
3853          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3854   "TARGET_64BIT"
3855   "movs{<imodesuffix>q|x}\t{%1, %0|%0, %1}"
3856   [(set_attr "type" "imovx")
3857    (set_attr "mode" "DI")])
3858
3859 (define_insn "extendhisi2"
3860   [(set (match_operand:SI 0 "register_operand" "=*a,r")
3861         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
3862   ""
3863 {
3864   switch (get_attr_prefix_0f (insn))
3865     {
3866     case 0:
3867       return "{cwtl|cwde}";
3868     default:
3869       return "movs{wl|x}\t{%1, %0|%0, %1}";
3870     }
3871 }
3872   [(set_attr "type" "imovx")
3873    (set_attr "mode" "SI")
3874    (set (attr "prefix_0f")
3875      ;; movsx is short decodable while cwtl is vector decoded.
3876      (if_then_else (and (eq_attr "cpu" "!k6")
3877                         (eq_attr "alternative" "0"))
3878         (const_string "0")
3879         (const_string "1")))
3880    (set (attr "modrm")
3881      (if_then_else (eq_attr "prefix_0f" "0")
3882         (const_string "0")
3883         (const_string "1")))])
3884
3885 (define_insn "*extendhisi2_zext"
3886   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3887         (zero_extend:DI
3888          (sign_extend:SI
3889           (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
3890   "TARGET_64BIT"
3891 {
3892   switch (get_attr_prefix_0f (insn))
3893     {
3894     case 0:
3895       return "{cwtl|cwde}";
3896     default:
3897       return "movs{wl|x}\t{%1, %k0|%k0, %1}";
3898     }
3899 }
3900   [(set_attr "type" "imovx")
3901    (set_attr "mode" "SI")
3902    (set (attr "prefix_0f")
3903      ;; movsx is short decodable while cwtl is vector decoded.
3904      (if_then_else (and (eq_attr "cpu" "!k6")
3905                         (eq_attr "alternative" "0"))
3906         (const_string "0")
3907         (const_string "1")))
3908    (set (attr "modrm")
3909      (if_then_else (eq_attr "prefix_0f" "0")
3910         (const_string "0")
3911         (const_string "1")))])
3912
3913 (define_insn "extendqisi2"
3914   [(set (match_operand:SI 0 "register_operand" "=r")
3915         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3916   ""
3917   "movs{bl|x}\t{%1, %0|%0, %1}"
3918    [(set_attr "type" "imovx")
3919     (set_attr "mode" "SI")])
3920
3921 (define_insn "*extendqisi2_zext"
3922   [(set (match_operand:DI 0 "register_operand" "=r")
3923         (zero_extend:DI
3924           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
3925   "TARGET_64BIT"
3926   "movs{bl|x}\t{%1, %k0|%k0, %1}"
3927    [(set_attr "type" "imovx")
3928     (set_attr "mode" "SI")])
3929
3930 (define_insn "extendqihi2"
3931   [(set (match_operand:HI 0 "register_operand" "=*a,r")
3932         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
3933   ""
3934 {
3935   switch (get_attr_prefix_0f (insn))
3936     {
3937     case 0:
3938       return "{cbtw|cbw}";
3939     default:
3940       return "movs{bw|x}\t{%1, %0|%0, %1}";
3941     }
3942 }
3943   [(set_attr "type" "imovx")
3944    (set_attr "mode" "HI")
3945    (set (attr "prefix_0f")
3946      ;; movsx is short decodable while cwtl is vector decoded.
3947      (if_then_else (and (eq_attr "cpu" "!k6")
3948                         (eq_attr "alternative" "0"))
3949         (const_string "0")
3950         (const_string "1")))
3951    (set (attr "modrm")
3952      (if_then_else (eq_attr "prefix_0f" "0")
3953         (const_string "0")
3954         (const_string "1")))])
3955 \f
3956 ;; Conversions between float and double.
3957
3958 ;; These are all no-ops in the model used for the 80387.
3959 ;; So just emit moves.
3960
3961 ;; %%% Kill these when call knows how to work out a DFmode push earlier.
3962 (define_split
3963   [(set (match_operand:DF 0 "push_operand")
3964         (float_extend:DF (match_operand:SF 1 "fp_register_operand")))]
3965   "reload_completed"
3966   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
3967    (set (mem:DF (reg:P SP_REG)) (float_extend:DF (match_dup 1)))])
3968
3969 (define_split
3970   [(set (match_operand:XF 0 "push_operand")
3971         (float_extend:XF (match_operand:MODEF 1 "fp_register_operand")))]
3972   "reload_completed"
3973   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
3974    (set (mem:XF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
3975   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
3976
3977 (define_expand "extendsfdf2"
3978   [(set (match_operand:DF 0 "nonimmediate_operand")
3979         (float_extend:DF (match_operand:SF 1 "general_operand")))]
3980   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
3981 {
3982   /* ??? Needed for compress_float_constant since all fp constants
3983      are TARGET_LEGITIMATE_CONSTANT_P.  */
3984   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3985     {
3986       if ((!TARGET_SSE2 || TARGET_MIX_SSE_I387)
3987           && standard_80387_constant_p (operands[1]) > 0)
3988         {
3989           operands[1] = simplify_const_unary_operation
3990             (FLOAT_EXTEND, DFmode, operands[1], SFmode);
3991           emit_move_insn_1 (operands[0], operands[1]);
3992           DONE;
3993         }
3994       operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
3995     }
3996 })
3997
3998 /* For converting SF(xmm2) to DF(xmm1), use the following code instead of
3999    cvtss2sd:
4000       unpcklps xmm2,xmm2   ; packed conversion might crash on signaling NaNs
4001       cvtps2pd xmm2,xmm1
4002    We do the conversion post reload to avoid producing of 128bit spills
4003    that might lead to ICE on 32bit target.  The sequence unlikely combine
4004    anyway.  */
4005 (define_split
4006   [(set (match_operand:DF 0 "register_operand")
4007         (float_extend:DF
4008           (match_operand:SF 1 "nonimmediate_operand")))]
4009   "TARGET_USE_VECTOR_FP_CONVERTS
4010    && optimize_insn_for_speed_p ()
4011    && reload_completed && SSE_REG_P (operands[0])"
4012    [(set (match_dup 2)
4013          (float_extend:V2DF
4014            (vec_select:V2SF
4015              (match_dup 3)
4016              (parallel [(const_int 0) (const_int 1)]))))]
4017 {
4018   operands[2] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
4019   operands[3] = simplify_gen_subreg (V4SFmode, operands[0], DFmode, 0);
4020   /* Use movss for loading from memory, unpcklps reg, reg for registers.
4021      Try to avoid move when unpacking can be done in source.  */
4022   if (REG_P (operands[1]))
4023     {
4024       /* If it is unsafe to overwrite upper half of source, we need
4025          to move to destination and unpack there.  */
4026       if ((ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4027            || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 4)
4028           && true_regnum (operands[0]) != true_regnum (operands[1]))
4029         {
4030           rtx tmp = gen_rtx_REG (SFmode, true_regnum (operands[0]));
4031           emit_move_insn (tmp, operands[1]);
4032         }
4033       else
4034         operands[3] = simplify_gen_subreg (V4SFmode, operands[1], SFmode, 0);
4035       emit_insn (gen_vec_interleave_lowv4sf (operands[3], operands[3],
4036                                              operands[3]));
4037     }
4038   else
4039     emit_insn (gen_vec_setv4sf_0 (operands[3],
4040                                   CONST0_RTX (V4SFmode), operands[1]));
4041 })
4042
4043 ;; It's more profitable to split and then extend in the same register.
4044 (define_peephole2
4045   [(set (match_operand:DF 0 "register_operand")
4046         (float_extend:DF
4047           (match_operand:SF 1 "memory_operand")))]
4048   "TARGET_SPLIT_MEM_OPND_FOR_FP_CONVERTS
4049    && optimize_insn_for_speed_p ()
4050    && SSE_REG_P (operands[0])"
4051   [(set (match_dup 2) (match_dup 1))
4052    (set (match_dup 0) (float_extend:DF (match_dup 2)))]
4053   "operands[2] = gen_rtx_REG (SFmode, REGNO (operands[0]));")
4054
4055 (define_insn "*extendsfdf2_mixed"
4056   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m,x")
4057         (float_extend:DF
4058           (match_operand:SF 1 "nonimmediate_operand" "fm,f,xm")))]
4059   "TARGET_SSE2 && TARGET_MIX_SSE_I387"
4060 {
4061   switch (which_alternative)
4062     {
4063     case 0:
4064     case 1:
4065       return output_387_reg_move (insn, operands);
4066
4067     case 2:
4068       return "%vcvtss2sd\t{%1, %d0|%d0, %1}";
4069
4070     default:
4071       gcc_unreachable ();
4072     }
4073 }
4074   [(set_attr "type" "fmov,fmov,ssecvt")
4075    (set_attr "prefix" "orig,orig,maybe_vex")
4076    (set_attr "mode" "SF,XF,DF")])
4077
4078 (define_insn "*extendsfdf2_sse"
4079   [(set (match_operand:DF 0 "nonimmediate_operand" "=x")
4080         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
4081   "TARGET_SSE2 && TARGET_SSE_MATH"
4082   "%vcvtss2sd\t{%1, %d0|%d0, %1}"
4083   [(set_attr "type" "ssecvt")
4084    (set_attr "prefix" "maybe_vex")
4085    (set_attr "mode" "DF")])
4086
4087 (define_insn "*extendsfdf2_i387"
4088   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m")
4089         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
4090   "TARGET_80387"
4091   "* return output_387_reg_move (insn, operands);"
4092   [(set_attr "type" "fmov")
4093    (set_attr "mode" "SF,XF")])
4094
4095 (define_expand "extend<mode>xf2"
4096   [(set (match_operand:XF 0 "nonimmediate_operand")
4097         (float_extend:XF (match_operand:MODEF 1 "general_operand")))]
4098   "TARGET_80387"
4099 {
4100   /* ??? Needed for compress_float_constant since all fp constants
4101      are TARGET_LEGITIMATE_CONSTANT_P.  */
4102   if (GET_CODE (operands[1]) == CONST_DOUBLE)
4103     {
4104       if (standard_80387_constant_p (operands[1]) > 0)
4105         {
4106           operands[1] = simplify_const_unary_operation
4107             (FLOAT_EXTEND, XFmode, operands[1], <MODE>mode);
4108           emit_move_insn_1 (operands[0], operands[1]);
4109           DONE;
4110         }
4111       operands[1] = validize_mem (force_const_mem (<MODE>mode, operands[1]));
4112     }
4113 })
4114
4115 (define_insn "*extend<mode>xf2_i387"
4116   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
4117         (float_extend:XF
4118           (match_operand:MODEF 1 "nonimmediate_operand" "fm,f")))]
4119   "TARGET_80387"
4120   "* return output_387_reg_move (insn, operands);"
4121   [(set_attr "type" "fmov")
4122    (set_attr "mode" "<MODE>,XF")])
4123
4124 ;; %%% This seems bad bad news.
4125 ;; This cannot output into an f-reg because there is no way to be sure
4126 ;; of truncating in that case.  Otherwise this is just like a simple move
4127 ;; insn.  So we pretend we can output to a reg in order to get better
4128 ;; register preferencing, but we really use a stack slot.
4129
4130 ;; Conversion from DFmode to SFmode.
4131
4132 (define_expand "truncdfsf2"
4133   [(set (match_operand:SF 0 "nonimmediate_operand")
4134         (float_truncate:SF
4135           (match_operand:DF 1 "nonimmediate_operand")))]
4136   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
4137 {
4138   if (TARGET_SSE2 && TARGET_SSE_MATH && !TARGET_MIX_SSE_I387)
4139     ;
4140   else if (flag_unsafe_math_optimizations)
4141     ;
4142   else
4143     {
4144       rtx temp = assign_386_stack_local (SFmode, SLOT_TEMP);
4145       emit_insn (gen_truncdfsf2_with_temp (operands[0], operands[1], temp));
4146       DONE;
4147     }
4148 })
4149
4150 /* For converting DF(xmm2) to SF(xmm1), use the following code instead of
4151    cvtsd2ss:
4152       unpcklpd xmm2,xmm2   ; packed conversion might crash on signaling NaNs
4153       cvtpd2ps xmm2,xmm1
4154    We do the conversion post reload to avoid producing of 128bit spills
4155    that might lead to ICE on 32bit target.  The sequence unlikely combine
4156    anyway.  */
4157 (define_split
4158   [(set (match_operand:SF 0 "register_operand")
4159         (float_truncate:SF
4160           (match_operand:DF 1 "nonimmediate_operand")))]
4161   "TARGET_USE_VECTOR_FP_CONVERTS
4162    && optimize_insn_for_speed_p ()
4163    && reload_completed && SSE_REG_P (operands[0])"
4164    [(set (match_dup 2)
4165          (vec_concat:V4SF
4166            (float_truncate:V2SF
4167              (match_dup 4))
4168            (match_dup 3)))]
4169 {
4170   operands[2] = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4171   operands[3] = CONST0_RTX (V2SFmode);
4172   operands[4] = simplify_gen_subreg (V2DFmode, operands[0], SFmode, 0);
4173   /* Use movsd for loading from memory, unpcklpd for registers.
4174      Try to avoid move when unpacking can be done in source, or SSE3
4175      movddup is available.  */
4176   if (REG_P (operands[1]))
4177     {
4178       if (!TARGET_SSE3
4179           && true_regnum (operands[0]) != true_regnum (operands[1])
4180           && (ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4181               || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 8))
4182         {
4183           rtx tmp = simplify_gen_subreg (DFmode, operands[0], SFmode, 0);
4184           emit_move_insn (tmp, operands[1]);
4185           operands[1] = tmp;
4186         }
4187       else if (!TARGET_SSE3)
4188         operands[4] = simplify_gen_subreg (V2DFmode, operands[1], DFmode, 0);
4189       emit_insn (gen_vec_dupv2df (operands[4], operands[1]));
4190     }
4191   else
4192     emit_insn (gen_sse2_loadlpd (operands[4],
4193                                  CONST0_RTX (V2DFmode), operands[1]));
4194 })
4195
4196 ;; It's more profitable to split and then extend in the same register.
4197 (define_peephole2
4198   [(set (match_operand:SF 0 "register_operand")
4199         (float_truncate:SF
4200           (match_operand:DF 1 "memory_operand")))]
4201   "TARGET_SPLIT_MEM_OPND_FOR_FP_CONVERTS
4202    && optimize_insn_for_speed_p ()
4203    && SSE_REG_P (operands[0])"
4204   [(set (match_dup 2) (match_dup 1))
4205    (set (match_dup 0) (float_truncate:SF (match_dup 2)))]
4206   "operands[2] = gen_rtx_REG (DFmode, REGNO (operands[0]));")
4207
4208 (define_expand "truncdfsf2_with_temp"
4209   [(parallel [(set (match_operand:SF 0)
4210                    (float_truncate:SF (match_operand:DF 1)))
4211               (clobber (match_operand:SF 2))])])
4212
4213 (define_insn "*truncdfsf_fast_mixed"
4214   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm,x")
4215         (float_truncate:SF
4216           (match_operand:DF 1 "nonimmediate_operand" "f  ,xm")))]
4217   "TARGET_SSE2 && TARGET_MIX_SSE_I387 && flag_unsafe_math_optimizations"
4218 {
4219   switch (which_alternative)
4220     {
4221     case 0:
4222       return output_387_reg_move (insn, operands);
4223     case 1:
4224       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4225     default:
4226       gcc_unreachable ();
4227     }
4228 }
4229   [(set_attr "type" "fmov,ssecvt")
4230    (set_attr "prefix" "orig,maybe_vex")
4231    (set_attr "mode" "SF")])
4232
4233 ;; Yes, this one doesn't depend on flag_unsafe_math_optimizations,
4234 ;; because nothing we do here is unsafe.
4235 (define_insn "*truncdfsf_fast_sse"
4236   [(set (match_operand:SF 0 "nonimmediate_operand"   "=x")
4237         (float_truncate:SF
4238           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
4239   "TARGET_SSE2 && TARGET_SSE_MATH"
4240   "%vcvtsd2ss\t{%1, %d0|%d0, %1}"
4241   [(set_attr "type" "ssecvt")
4242    (set_attr "prefix" "maybe_vex")
4243    (set_attr "mode" "SF")])
4244
4245 (define_insn "*truncdfsf_fast_i387"
4246   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm")
4247         (float_truncate:SF
4248           (match_operand:DF 1 "nonimmediate_operand" "f")))]
4249   "TARGET_80387 && flag_unsafe_math_optimizations"
4250   "* return output_387_reg_move (insn, operands);"
4251   [(set_attr "type" "fmov")
4252    (set_attr "mode" "SF")])
4253
4254 (define_insn "*truncdfsf_mixed"
4255   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,x ,?f,?x,?*r")
4256         (float_truncate:SF
4257           (match_operand:DF 1 "nonimmediate_operand" "f ,xm,f ,f ,f")))
4258    (clobber (match_operand:SF 2 "memory_operand"     "=X,X ,m ,m ,m"))]
4259   "TARGET_MIX_SSE_I387"
4260 {
4261   switch (which_alternative)
4262     {
4263     case 0:
4264       return output_387_reg_move (insn, operands);
4265     case 1:
4266       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4267
4268     default:
4269       return "#";
4270     }
4271 }
4272   [(set_attr "isa" "*,sse2,*,*,*")
4273    (set_attr "type" "fmov,ssecvt,multi,multi,multi")
4274    (set_attr "unit" "*,*,i387,i387,i387")
4275    (set_attr "prefix" "orig,maybe_vex,orig,orig,orig")
4276    (set_attr "mode" "SF")])
4277
4278 (define_insn "*truncdfsf_i387"
4279   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,?f,?x,?*r")
4280         (float_truncate:SF
4281           (match_operand:DF 1 "nonimmediate_operand" "f ,f ,f ,f")))
4282    (clobber (match_operand:SF 2 "memory_operand"     "=X,m ,m ,m"))]
4283   "TARGET_80387"
4284 {
4285   switch (which_alternative)
4286     {
4287     case 0:
4288       return output_387_reg_move (insn, operands);
4289
4290     default:
4291       return "#";
4292     }
4293 }
4294   [(set_attr "type" "fmov,multi,multi,multi")
4295    (set_attr "unit" "*,i387,i387,i387")
4296    (set_attr "mode" "SF")])
4297
4298 (define_insn "*truncdfsf2_i387_1"
4299   [(set (match_operand:SF 0 "memory_operand" "=m")
4300         (float_truncate:SF
4301           (match_operand:DF 1 "register_operand" "f")))]
4302   "TARGET_80387
4303    && !(TARGET_SSE2 && TARGET_SSE_MATH)
4304    && !TARGET_MIX_SSE_I387"
4305   "* return output_387_reg_move (insn, operands);"
4306   [(set_attr "type" "fmov")
4307    (set_attr "mode" "SF")])
4308
4309 (define_split
4310   [(set (match_operand:SF 0 "register_operand")
4311         (float_truncate:SF
4312          (match_operand:DF 1 "fp_register_operand")))
4313    (clobber (match_operand 2))]
4314   "reload_completed"
4315   [(set (match_dup 2) (match_dup 1))
4316    (set (match_dup 0) (match_dup 2))]
4317   "operands[1] = gen_rtx_REG (SFmode, true_regnum (operands[1]));")
4318
4319 ;; Conversion from XFmode to {SF,DF}mode
4320
4321 (define_expand "truncxf<mode>2"
4322   [(parallel [(set (match_operand:MODEF 0 "nonimmediate_operand")
4323                    (float_truncate:MODEF
4324                      (match_operand:XF 1 "register_operand")))
4325               (clobber (match_dup 2))])]
4326   "TARGET_80387"
4327 {
4328   if (flag_unsafe_math_optimizations)
4329     {
4330       rtx reg = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (<MODE>mode);
4331       emit_insn (gen_truncxf<mode>2_i387_noop (reg, operands[1]));
4332       if (reg != operands[0])
4333         emit_move_insn (operands[0], reg);
4334       DONE;
4335     }
4336   else
4337     operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4338 })
4339
4340 (define_insn "*truncxfsf2_mixed"
4341   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f,?x,?*r")
4342         (float_truncate:SF
4343           (match_operand:XF 1 "register_operand"   "f ,f ,f ,f")))
4344    (clobber (match_operand:SF 2 "memory_operand"   "=X,m ,m ,m"))]
4345   "TARGET_80387"
4346 {
4347   gcc_assert (!which_alternative);
4348   return output_387_reg_move (insn, operands);
4349 }
4350   [(set_attr "type" "fmov,multi,multi,multi")
4351    (set_attr "unit" "*,i387,i387,i387")
4352    (set_attr "mode" "SF")])
4353
4354 (define_insn "*truncxfdf2_mixed"
4355   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f,?x,?*r")
4356         (float_truncate:DF
4357           (match_operand:XF 1 "register_operand"   "f ,f ,f  ,f")))
4358    (clobber (match_operand:DF 2 "memory_operand"   "=X,m ,m  ,m"))]
4359   "TARGET_80387"
4360 {
4361   gcc_assert (!which_alternative);
4362   return output_387_reg_move (insn, operands);
4363 }
4364   [(set_attr "isa" "*,*,sse2,*")
4365    (set_attr "type" "fmov,multi,multi,multi")
4366    (set_attr "unit" "*,i387,i387,i387")
4367    (set_attr "mode" "DF")])
4368
4369 (define_insn "truncxf<mode>2_i387_noop"
4370   [(set (match_operand:MODEF 0 "register_operand" "=f")
4371         (float_truncate:MODEF
4372           (match_operand:XF 1 "register_operand" "f")))]
4373   "TARGET_80387 && flag_unsafe_math_optimizations"
4374   "* return output_387_reg_move (insn, operands);"
4375   [(set_attr "type" "fmov")
4376    (set_attr "mode" "<MODE>")])
4377
4378 (define_insn "*truncxf<mode>2_i387"
4379   [(set (match_operand:MODEF 0 "memory_operand" "=m")
4380         (float_truncate:MODEF
4381           (match_operand:XF 1 "register_operand" "f")))]
4382   "TARGET_80387"
4383   "* return output_387_reg_move (insn, operands);"
4384   [(set_attr "type" "fmov")
4385    (set_attr "mode" "<MODE>")])
4386
4387 (define_split
4388   [(set (match_operand:MODEF 0 "register_operand")
4389         (float_truncate:MODEF
4390           (match_operand:XF 1 "register_operand")))
4391    (clobber (match_operand:MODEF 2 "memory_operand"))]
4392   "TARGET_80387 && reload_completed"
4393   [(set (match_dup 2) (float_truncate:MODEF (match_dup 1)))
4394    (set (match_dup 0) (match_dup 2))])
4395
4396 (define_split
4397   [(set (match_operand:MODEF 0 "memory_operand")
4398         (float_truncate:MODEF
4399           (match_operand:XF 1 "register_operand")))
4400    (clobber (match_operand:MODEF 2 "memory_operand"))]
4401   "TARGET_80387"
4402   [(set (match_dup 0) (float_truncate:MODEF (match_dup 1)))])
4403 \f
4404 ;; Signed conversion to DImode.
4405
4406 (define_expand "fix_truncxfdi2"
4407   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand")
4408                    (fix:DI (match_operand:XF 1 "register_operand")))
4409               (clobber (reg:CC FLAGS_REG))])]
4410   "TARGET_80387"
4411 {
4412   if (TARGET_FISTTP)
4413    {
4414      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4415      DONE;
4416    }
4417 })
4418
4419 (define_expand "fix_trunc<mode>di2"
4420   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand")
4421                    (fix:DI (match_operand:MODEF 1 "register_operand")))
4422               (clobber (reg:CC FLAGS_REG))])]
4423   "TARGET_80387 || (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))"
4424 {
4425   if (TARGET_FISTTP
4426       && !(TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
4427    {
4428      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4429      DONE;
4430    }
4431   if (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))
4432    {
4433      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4434      emit_insn (gen_fix_trunc<mode>di_sse (out, operands[1]));
4435      if (out != operands[0])
4436         emit_move_insn (operands[0], out);
4437      DONE;
4438    }
4439 })
4440
4441 ;; Signed conversion to SImode.
4442
4443 (define_expand "fix_truncxfsi2"
4444   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand")
4445                    (fix:SI (match_operand:XF 1 "register_operand")))
4446               (clobber (reg:CC FLAGS_REG))])]
4447   "TARGET_80387"
4448 {
4449   if (TARGET_FISTTP)
4450    {
4451      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
4452      DONE;
4453    }
4454 })
4455
4456 (define_expand "fix_trunc<mode>si2"
4457   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand")
4458                    (fix:SI (match_operand:MODEF 1 "register_operand")))
4459               (clobber (reg:CC FLAGS_REG))])]
4460   "TARGET_80387 || SSE_FLOAT_MODE_P (<MODE>mode)"
4461 {
4462   if (TARGET_FISTTP
4463       && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
4464    {
4465      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
4466      DONE;
4467    }
4468   if (SSE_FLOAT_MODE_P (<MODE>mode))
4469    {
4470      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
4471      emit_insn (gen_fix_trunc<mode>si_sse (out, operands[1]));
4472      if (out != operands[0])
4473         emit_move_insn (operands[0], out);
4474      DONE;
4475    }
4476 })
4477
4478 ;; Signed conversion to HImode.
4479
4480 (define_expand "fix_trunc<mode>hi2"
4481   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand")
4482                    (fix:HI (match_operand:X87MODEF 1 "register_operand")))
4483               (clobber (reg:CC FLAGS_REG))])]
4484   "TARGET_80387
4485    && !(SSE_FLOAT_MODE_P (<MODE>mode) && (!TARGET_FISTTP || TARGET_SSE_MATH))"
4486 {
4487   if (TARGET_FISTTP)
4488    {
4489      emit_insn (gen_fix_trunchi_fisttp_i387_1 (operands[0], operands[1]));
4490      DONE;
4491    }
4492 })
4493
4494 ;; Unsigned conversion to SImode.
4495
4496 (define_expand "fixuns_trunc<mode>si2"
4497   [(parallel
4498     [(set (match_operand:SI 0 "register_operand")
4499           (unsigned_fix:SI
4500             (match_operand:MODEF 1 "nonimmediate_operand")))
4501      (use (match_dup 2))
4502      (clobber (match_scratch:<ssevecmode> 3))
4503      (clobber (match_scratch:<ssevecmode> 4))])]
4504   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH"
4505 {
4506   machine_mode mode = <MODE>mode;
4507   machine_mode vecmode = <ssevecmode>mode;
4508   REAL_VALUE_TYPE TWO31r;
4509   rtx two31;
4510
4511   if (optimize_insn_for_size_p ())
4512     FAIL;
4513
4514   real_ldexp (&TWO31r, &dconst1, 31);
4515   two31 = const_double_from_real_value (TWO31r, mode);
4516   two31 = ix86_build_const_vector (vecmode, true, two31);
4517   operands[2] = force_reg (vecmode, two31);
4518 })
4519
4520 (define_insn_and_split "*fixuns_trunc<mode>_1"
4521   [(set (match_operand:SI 0 "register_operand" "=&x,&x")
4522         (unsigned_fix:SI
4523           (match_operand:MODEF 3 "nonimmediate_operand" "xm,xm")))
4524    (use (match_operand:<ssevecmode> 4  "nonimmediate_operand" "m,x"))
4525    (clobber (match_scratch:<ssevecmode> 1 "=x,&x"))
4526    (clobber (match_scratch:<ssevecmode> 2 "=x,x"))]
4527   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH
4528    && optimize_function_for_speed_p (cfun)"
4529   "#"
4530   "&& reload_completed"
4531   [(const_int 0)]
4532 {
4533   ix86_split_convert_uns_si_sse (operands);
4534   DONE;
4535 })
4536
4537 ;; Unsigned conversion to HImode.
4538 ;; Without these patterns, we'll try the unsigned SI conversion which
4539 ;; is complex for SSE, rather than the signed SI conversion, which isn't.
4540
4541 (define_expand "fixuns_trunc<mode>hi2"
4542   [(set (match_dup 2)
4543         (fix:SI (match_operand:MODEF 1 "nonimmediate_operand")))
4544    (set (match_operand:HI 0 "nonimmediate_operand")
4545         (subreg:HI (match_dup 2) 0))]
4546   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
4547   "operands[2] = gen_reg_rtx (SImode);")
4548
4549 ;; When SSE is available, it is always faster to use it!
4550 (define_insn "fix_trunc<MODEF:mode><SWI48:mode>_sse"
4551   [(set (match_operand:SWI48 0 "register_operand" "=r,r")
4552         (fix:SWI48 (match_operand:MODEF 1 "nonimmediate_operand" "x,m")))]
4553   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode)
4554    && (!TARGET_FISTTP || TARGET_SSE_MATH)"
4555   "%vcvtt<MODEF:ssemodesuffix>2si<SWI48:rex64suffix>\t{%1, %0|%0, %1}"
4556   [(set_attr "type" "sseicvt")
4557    (set_attr "prefix" "maybe_vex")
4558    (set (attr "prefix_rex")
4559         (if_then_else
4560           (match_test "<SWI48:MODE>mode == DImode")
4561           (const_string "1")
4562           (const_string "*")))
4563    (set_attr "mode" "<MODEF:MODE>")
4564    (set_attr "athlon_decode" "double,vector")
4565    (set_attr "amdfam10_decode" "double,double")
4566    (set_attr "bdver1_decode" "double,double")])
4567
4568 ;; Avoid vector decoded forms of the instruction.
4569 (define_peephole2
4570   [(match_scratch:MODEF 2 "x")
4571    (set (match_operand:SWI48 0 "register_operand")
4572         (fix:SWI48 (match_operand:MODEF 1 "memory_operand")))]
4573   "TARGET_AVOID_VECTOR_DECODE
4574    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode)
4575    && optimize_insn_for_speed_p ()"
4576   [(set (match_dup 2) (match_dup 1))
4577    (set (match_dup 0) (fix:SWI48 (match_dup 2)))])
4578
4579 (define_insn_and_split "fix_trunc<mode>_fisttp_i387_1"
4580   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
4581         (fix:SWI248x (match_operand 1 "register_operand")))]
4582   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4583    && TARGET_FISTTP
4584    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4585          && (TARGET_64BIT || <MODE>mode != DImode))
4586         && TARGET_SSE_MATH)
4587    && can_create_pseudo_p ()"
4588   "#"
4589   "&& 1"
4590   [(const_int 0)]
4591 {
4592   if (memory_operand (operands[0], VOIDmode))
4593     emit_insn (gen_fix_trunc<mode>_i387_fisttp (operands[0], operands[1]));
4594   else
4595     {
4596       operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4597       emit_insn (gen_fix_trunc<mode>_i387_fisttp_with_temp (operands[0],
4598                                                             operands[1],
4599                                                             operands[2]));
4600     }
4601   DONE;
4602 }
4603   [(set_attr "type" "fisttp")
4604    (set_attr "mode" "<MODE>")])
4605
4606 (define_insn "fix_trunc<mode>_i387_fisttp"
4607   [(set (match_operand:SWI248x 0 "memory_operand" "=m")
4608         (fix:SWI248x (match_operand 1 "register_operand" "f")))
4609    (clobber (match_scratch:XF 2 "=&1f"))]
4610   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4611    && TARGET_FISTTP
4612    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4613          && (TARGET_64BIT || <MODE>mode != DImode))
4614         && TARGET_SSE_MATH)"
4615   "* return output_fix_trunc (insn, operands, true);"
4616   [(set_attr "type" "fisttp")
4617    (set_attr "mode" "<MODE>")])
4618
4619 (define_insn "fix_trunc<mode>_i387_fisttp_with_temp"
4620   [(set (match_operand:SWI248x 0 "nonimmediate_operand" "=m,?r")
4621         (fix:SWI248x (match_operand 1 "register_operand" "f,f")))
4622    (clobber (match_operand:SWI248x 2 "memory_operand" "=X,m"))
4623    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
4624   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4625    && TARGET_FISTTP
4626    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4627         && (TARGET_64BIT || <MODE>mode != DImode))
4628         && TARGET_SSE_MATH)"
4629   "#"
4630   [(set_attr "type" "fisttp")
4631    (set_attr "mode" "<MODE>")])
4632
4633 (define_split
4634   [(set (match_operand:SWI248x 0 "register_operand")
4635         (fix:SWI248x (match_operand 1 "register_operand")))
4636    (clobber (match_operand:SWI248x 2 "memory_operand"))
4637    (clobber (match_scratch 3))]
4638   "reload_completed"
4639   [(parallel [(set (match_dup 2) (fix:SWI248x (match_dup 1)))
4640               (clobber (match_dup 3))])
4641    (set (match_dup 0) (match_dup 2))])
4642
4643 (define_split
4644   [(set (match_operand:SWI248x 0 "memory_operand")
4645         (fix:SWI248x (match_operand 1 "register_operand")))
4646    (clobber (match_operand:SWI248x 2 "memory_operand"))
4647    (clobber (match_scratch 3))]
4648   "reload_completed"
4649   [(parallel [(set (match_dup 0) (fix:SWI248x (match_dup 1)))
4650               (clobber (match_dup 3))])])
4651
4652 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4653 ;; of the machinery. Please note the clobber of FLAGS_REG. In i387 control
4654 ;; word calculation (inserted by LCM in mode switching pass) a FLAGS_REG
4655 ;; clobbering insns can be used. Look at emit_i387_cw_initialization ()
4656 ;; function in i386.c.
4657 (define_insn_and_split "*fix_trunc<mode>_i387_1"
4658   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
4659         (fix:SWI248x (match_operand 1 "register_operand")))
4660    (clobber (reg:CC FLAGS_REG))]
4661   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4662    && !TARGET_FISTTP
4663    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4664          && (TARGET_64BIT || <MODE>mode != DImode))
4665    && can_create_pseudo_p ()"
4666   "#"
4667   "&& 1"
4668   [(const_int 0)]
4669 {
4670   ix86_optimize_mode_switching[I387_TRUNC] = 1;
4671
4672   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
4673   operands[3] = assign_386_stack_local (HImode, SLOT_CW_TRUNC);
4674   if (memory_operand (operands[0], VOIDmode))
4675     emit_insn (gen_fix_trunc<mode>_i387 (operands[0], operands[1],
4676                                          operands[2], operands[3]));
4677   else
4678     {
4679       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4680       emit_insn (gen_fix_trunc<mode>_i387_with_temp (operands[0], operands[1],
4681                                                      operands[2], operands[3],
4682                                                      operands[4]));
4683     }
4684   DONE;
4685 }
4686   [(set_attr "type" "fistp")
4687    (set_attr "i387_cw" "trunc")
4688    (set_attr "mode" "<MODE>")])
4689
4690 (define_insn "fix_truncdi_i387"
4691   [(set (match_operand:DI 0 "memory_operand" "=m")
4692         (fix:DI (match_operand 1 "register_operand" "f")))
4693    (use (match_operand:HI 2 "memory_operand" "m"))
4694    (use (match_operand:HI 3 "memory_operand" "m"))
4695    (clobber (match_scratch:XF 4 "=&1f"))]
4696   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4697    && !TARGET_FISTTP
4698    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
4699   "* return output_fix_trunc (insn, operands, false);"
4700   [(set_attr "type" "fistp")
4701    (set_attr "i387_cw" "trunc")
4702    (set_attr "mode" "DI")])
4703
4704 (define_insn "fix_truncdi_i387_with_temp"
4705   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
4706         (fix:DI (match_operand 1 "register_operand" "f,f")))
4707    (use (match_operand:HI 2 "memory_operand" "m,m"))
4708    (use (match_operand:HI 3 "memory_operand" "m,m"))
4709    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
4710    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
4711   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4712    && !TARGET_FISTTP
4713    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
4714   "#"
4715   [(set_attr "type" "fistp")
4716    (set_attr "i387_cw" "trunc")
4717    (set_attr "mode" "DI")])
4718
4719 (define_split
4720   [(set (match_operand:DI 0 "register_operand")
4721         (fix:DI (match_operand 1 "register_operand")))
4722    (use (match_operand:HI 2 "memory_operand"))
4723    (use (match_operand:HI 3 "memory_operand"))
4724    (clobber (match_operand:DI 4 "memory_operand"))
4725    (clobber (match_scratch 5))]
4726   "reload_completed"
4727   [(parallel [(set (match_dup 4) (fix:DI (match_dup 1)))
4728               (use (match_dup 2))
4729               (use (match_dup 3))
4730               (clobber (match_dup 5))])
4731    (set (match_dup 0) (match_dup 4))])
4732
4733 (define_split
4734   [(set (match_operand:DI 0 "memory_operand")
4735         (fix:DI (match_operand 1 "register_operand")))
4736    (use (match_operand:HI 2 "memory_operand"))
4737    (use (match_operand:HI 3 "memory_operand"))
4738    (clobber (match_operand:DI 4 "memory_operand"))
4739    (clobber (match_scratch 5))]
4740   "reload_completed"
4741   [(parallel [(set (match_dup 0) (fix:DI (match_dup 1)))
4742               (use (match_dup 2))
4743               (use (match_dup 3))
4744               (clobber (match_dup 5))])])
4745
4746 (define_insn "fix_trunc<mode>_i387"
4747   [(set (match_operand:SWI24 0 "memory_operand" "=m")
4748         (fix:SWI24 (match_operand 1 "register_operand" "f")))
4749    (use (match_operand:HI 2 "memory_operand" "m"))
4750    (use (match_operand:HI 3 "memory_operand" "m"))]
4751   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4752    && !TARGET_FISTTP
4753    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4754   "* return output_fix_trunc (insn, operands, false);"
4755   [(set_attr "type" "fistp")
4756    (set_attr "i387_cw" "trunc")
4757    (set_attr "mode" "<MODE>")])
4758
4759 (define_insn "fix_trunc<mode>_i387_with_temp"
4760   [(set (match_operand:SWI24 0 "nonimmediate_operand" "=m,?r")
4761         (fix:SWI24 (match_operand 1 "register_operand" "f,f")))
4762    (use (match_operand:HI 2 "memory_operand" "m,m"))
4763    (use (match_operand:HI 3 "memory_operand" "m,m"))
4764    (clobber (match_operand:SWI24 4 "memory_operand" "=X,m"))]
4765   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4766    && !TARGET_FISTTP
4767    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4768   "#"
4769   [(set_attr "type" "fistp")
4770    (set_attr "i387_cw" "trunc")
4771    (set_attr "mode" "<MODE>")])
4772
4773 (define_split
4774   [(set (match_operand:SWI24 0 "register_operand")
4775         (fix:SWI24 (match_operand 1 "register_operand")))
4776    (use (match_operand:HI 2 "memory_operand"))
4777    (use (match_operand:HI 3 "memory_operand"))
4778    (clobber (match_operand:SWI24 4 "memory_operand"))]
4779   "reload_completed"
4780   [(parallel [(set (match_dup 4) (fix:SWI24 (match_dup 1)))
4781               (use (match_dup 2))
4782               (use (match_dup 3))])
4783    (set (match_dup 0) (match_dup 4))])
4784
4785 (define_split
4786   [(set (match_operand:SWI24 0 "memory_operand")
4787         (fix:SWI24 (match_operand 1 "register_operand")))
4788    (use (match_operand:HI 2 "memory_operand"))
4789    (use (match_operand:HI 3 "memory_operand"))
4790    (clobber (match_operand:SWI24 4 "memory_operand"))]
4791   "reload_completed"
4792   [(parallel [(set (match_dup 0) (fix:SWI24 (match_dup 1)))
4793               (use (match_dup 2))
4794               (use (match_dup 3))])])
4795
4796 (define_insn "x86_fnstcw_1"
4797   [(set (match_operand:HI 0 "memory_operand" "=m")
4798         (unspec:HI [(reg:HI FPCR_REG)] UNSPEC_FSTCW))]
4799   "TARGET_80387"
4800   "fnstcw\t%0"
4801   [(set (attr "length")
4802         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
4803    (set_attr "mode" "HI")
4804    (set_attr "unit" "i387")
4805    (set_attr "bdver1_decode" "vector")])
4806
4807 (define_insn "x86_fldcw_1"
4808   [(set (reg:HI FPCR_REG)
4809         (unspec:HI [(match_operand:HI 0 "memory_operand" "m")] UNSPEC_FLDCW))]
4810   "TARGET_80387"
4811   "fldcw\t%0"
4812   [(set (attr "length")
4813         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
4814    (set_attr "mode" "HI")
4815    (set_attr "unit" "i387")
4816    (set_attr "athlon_decode" "vector")
4817    (set_attr "amdfam10_decode" "vector")
4818    (set_attr "bdver1_decode" "vector")])
4819 \f
4820 ;; Conversion between fixed point and floating point.
4821
4822 ;; Even though we only accept memory inputs, the backend _really_
4823 ;; wants to be able to do this between registers.  Thankfully, LRA
4824 ;; will fix this up for us during register allocation.
4825
4826 (define_insn "floathi<mode>2"
4827   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
4828         (float:X87MODEF (match_operand:HI 1 "nonimmediate_operand" "m")))]
4829   "TARGET_80387
4830    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4831        || TARGET_MIX_SSE_I387)"
4832   "fild%Z1\t%1"
4833   [(set_attr "type" "fmov")
4834    (set_attr "mode" "<MODE>")
4835    (set_attr "fp_int_src" "true")])
4836
4837 (define_insn "float<SWI48x:mode>xf2"
4838   [(set (match_operand:XF 0 "register_operand" "=f")
4839         (float:XF (match_operand:SWI48x 1 "nonimmediate_operand" "m")))]
4840   "TARGET_80387"
4841   "fild%Z1\t%1"
4842   [(set_attr "type" "fmov")
4843    (set_attr "mode" "XF")
4844    (set_attr "fp_int_src" "true")])
4845
4846 (define_expand "float<SWI48:mode><MODEF:mode>2"
4847   [(set (match_operand:MODEF 0 "register_operand")
4848         (float:MODEF (match_operand:SWI48 1 "nonimmediate_operand")))]
4849   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)"
4850 {
4851   if (!(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
4852       && !X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI48:MODE>mode))
4853     {
4854       rtx reg = gen_reg_rtx (XFmode);
4855       rtx (*insn)(rtx, rtx);
4856
4857       emit_insn (gen_float<SWI48:mode>xf2 (reg, operands[1]));
4858
4859       if (<MODEF:MODE>mode == SFmode)
4860         insn = gen_truncxfsf2;
4861       else if (<MODEF:MODE>mode == DFmode)
4862         insn = gen_truncxfdf2;
4863       else
4864         gcc_unreachable ();
4865
4866       emit_insn (insn (operands[0], reg));
4867       DONE;
4868     }
4869 })
4870
4871 (define_insn "*float<SWI48:mode><MODEF:mode>2_sse"
4872   [(set (match_operand:MODEF 0 "register_operand" "=f,x,x")
4873         (float:MODEF
4874           (match_operand:SWI48 1 "nonimmediate_operand" "m,r,m")))]
4875   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH"
4876   "@
4877    fild%Z1\t%1
4878    %vcvtsi2<MODEF:ssemodesuffix><SWI48:rex64suffix>\t{%1, %d0|%d0, %1}
4879    %vcvtsi2<MODEF:ssemodesuffix><SWI48:rex64suffix>\t{%1, %d0|%d0, %1}"
4880   [(set_attr "type" "fmov,sseicvt,sseicvt")
4881    (set_attr "prefix" "orig,maybe_vex,maybe_vex")
4882    (set_attr "mode" "<MODEF:MODE>")
4883    (set (attr "prefix_rex")
4884      (if_then_else
4885        (and (eq_attr "prefix" "maybe_vex")
4886             (match_test "<SWI48:MODE>mode == DImode"))
4887        (const_string "1")
4888        (const_string "*")))
4889    (set_attr "unit" "i387,*,*")
4890    (set_attr "athlon_decode" "*,double,direct")
4891    (set_attr "amdfam10_decode" "*,vector,double")
4892    (set_attr "bdver1_decode" "*,double,direct")
4893    (set_attr "fp_int_src" "true")
4894    (set (attr "enabled")
4895      (cond [(eq_attr "alternative" "0")
4896               (symbol_ref "TARGET_MIX_SSE_I387
4897                            && X87_ENABLE_FLOAT (<MODEF:MODE>mode,
4898                                                 <SWI48:MODE>mode)")
4899            ]
4900            (symbol_ref "true")))
4901    (set (attr "preferred_for_speed")
4902      (cond [(eq_attr "alternative" "1")
4903               (symbol_ref "TARGET_INTER_UNIT_CONVERSIONS")]
4904            (symbol_ref "true")))])
4905
4906 (define_insn "*float<SWI48x:mode><MODEF:mode>2_i387"
4907   [(set (match_operand:MODEF 0 "register_operand" "=f")
4908         (float:MODEF (match_operand:SWI48x 1 "nonimmediate_operand" "m")))]
4909   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI48x:MODE>mode)"
4910   "fild%Z1\t%1"
4911   [(set_attr "type" "fmov")
4912    (set_attr "mode" "<MODEF:MODE>")
4913    (set_attr "fp_int_src" "true")])
4914
4915 ;; Try TARGET_USE_VECTOR_CONVERTS, but not so hard as to require extra memory
4916 ;; slots when !TARGET_INTER_UNIT_MOVES_TO_VEC disables the general_regs
4917 ;; alternative in sse2_loadld.
4918 (define_split
4919   [(set (match_operand:MODEF 0 "register_operand")
4920         (float:MODEF (match_operand:SI 1 "nonimmediate_operand")))]
4921   "TARGET_SSE2 && TARGET_SSE_MATH
4922    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
4923    && reload_completed && SSE_REG_P (operands[0])
4924    && (MEM_P (operands[1]) || TARGET_INTER_UNIT_MOVES_TO_VEC)"
4925   [(const_int 0)]
4926 {
4927   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
4928                                      <MODE>mode, 0);
4929   operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
4930
4931   emit_insn (gen_sse2_loadld (operands[4],
4932                               CONST0_RTX (V4SImode), operands[1]));
4933
4934   if (<ssevecmode>mode == V4SFmode)
4935     emit_insn (gen_floatv4siv4sf2 (operands[3], operands[4]));
4936   else
4937     emit_insn (gen_sse2_cvtdq2pd (operands[3], operands[4]));
4938   DONE;
4939 })
4940
4941 ;; Avoid partial SSE register dependency stalls
4942 (define_split
4943   [(set (match_operand:MODEF 0 "register_operand")
4944         (float:MODEF (match_operand:SWI48 1 "nonimmediate_operand")))]
4945   "TARGET_SSE2 && TARGET_SSE_MATH
4946    && TARGET_SSE_PARTIAL_REG_DEPENDENCY
4947    && optimize_function_for_speed_p (cfun)
4948    && reload_completed && SSE_REG_P (operands[0])"
4949   [(const_int 0)]
4950 {
4951   const machine_mode vmode = <MODEF:ssevecmode>mode;
4952   const machine_mode mode = <MODEF:MODE>mode;
4953   rtx t, op0 = simplify_gen_subreg (vmode, operands[0], mode, 0);
4954
4955   emit_move_insn (op0, CONST0_RTX (vmode));
4956
4957   t = gen_rtx_FLOAT (mode, operands[1]);
4958   t = gen_rtx_VEC_DUPLICATE (vmode, t);
4959   t = gen_rtx_VEC_MERGE (vmode, t, op0, const1_rtx);
4960   emit_insn (gen_rtx_SET (VOIDmode, op0, t));
4961   DONE;
4962 })
4963
4964 ;; Break partial reg stall for cvtsd2ss.
4965
4966 (define_peephole2
4967   [(set (match_operand:SF 0 "register_operand")
4968         (float_truncate:SF
4969           (match_operand:DF 1 "nonimmediate_operand")))]
4970   "TARGET_SSE2 && TARGET_SSE_MATH
4971    && TARGET_SSE_PARTIAL_REG_DEPENDENCY
4972    && optimize_function_for_speed_p (cfun)
4973    && SSE_REG_P (operands[0])
4974    && (!SSE_REG_P (operands[1])
4975        || REGNO (operands[0]) != REGNO (operands[1]))"
4976   [(set (match_dup 0)
4977         (vec_merge:V4SF
4978           (vec_duplicate:V4SF
4979             (float_truncate:V2SF
4980               (match_dup 1)))
4981           (match_dup 0)
4982           (const_int 1)))]
4983 {
4984   operands[0] = simplify_gen_subreg (V4SFmode, operands[0],
4985                                      SFmode, 0);
4986   operands[1] = simplify_gen_subreg (V2DFmode, operands[1],
4987                                      DFmode, 0);
4988   emit_move_insn (operands[0], CONST0_RTX (V4SFmode));
4989 })
4990
4991 ;; Break partial reg stall for cvtss2sd.
4992
4993 (define_peephole2
4994   [(set (match_operand:DF 0 "register_operand")
4995         (float_extend:DF
4996           (match_operand:SF 1 "nonimmediate_operand")))]
4997   "TARGET_SSE2 && TARGET_SSE_MATH
4998    && TARGET_SSE_PARTIAL_REG_DEPENDENCY
4999    && optimize_function_for_speed_p (cfun)
5000    && SSE_REG_P (operands[0])
5001    && (!SSE_REG_P (operands[1])
5002        || REGNO (operands[0]) != REGNO (operands[1]))"
5003   [(set (match_dup 0)
5004         (vec_merge:V2DF
5005           (float_extend:V2DF
5006             (vec_select:V2SF
5007               (match_dup 1)
5008               (parallel [(const_int 0) (const_int 1)])))
5009           (match_dup 0)
5010           (const_int 1)))]
5011 {
5012   operands[0] = simplify_gen_subreg (V2DFmode, operands[0],
5013                                      DFmode, 0);
5014   operands[1] = simplify_gen_subreg (V4SFmode, operands[1],
5015                                      SFmode, 0);
5016   emit_move_insn (operands[0], CONST0_RTX (V2DFmode));
5017 })
5018
5019 ;; Avoid store forwarding (partial memory) stall penalty
5020 ;; by passing DImode value through XMM registers.  */
5021
5022 (define_insn "floatdi<X87MODEF:mode>2_i387_with_xmm"
5023   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5024         (float:X87MODEF
5025           (match_operand:DI 1 "nonimmediate_operand" "m,?r")))
5026    (clobber (match_scratch:V4SI 3 "=X,x"))
5027    (clobber (match_scratch:V4SI 4 "=X,x"))
5028    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))]
5029   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5030    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC
5031    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)"
5032   "#"
5033   [(set_attr "type" "multi")
5034    (set_attr "mode" "<X87MODEF:MODE>")
5035    (set_attr "unit" "i387")
5036    (set_attr "fp_int_src" "true")])
5037
5038 (define_split
5039   [(set (match_operand:X87MODEF 0 "fp_register_operand")
5040         (float:X87MODEF (match_operand:DI 1 "register_operand")))
5041    (clobber (match_scratch:V4SI 3))
5042    (clobber (match_scratch:V4SI 4))
5043    (clobber (match_operand:DI 2 "memory_operand"))]
5044   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5045    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC
5046    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5047    && reload_completed"
5048   [(set (match_dup 2) (match_dup 3))
5049    (set (match_dup 0) (float:X87MODEF (match_dup 2)))]
5050 {
5051   /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
5052      Assemble the 64-bit DImode value in an xmm register.  */
5053   emit_insn (gen_sse2_loadld (operands[3], CONST0_RTX (V4SImode),
5054                               gen_lowpart (SImode, operands[1])));
5055   emit_insn (gen_sse2_loadld (operands[4], CONST0_RTX (V4SImode),
5056                               gen_highpart (SImode, operands[1])));
5057   emit_insn (gen_vec_interleave_lowv4si (operands[3], operands[3],
5058                                          operands[4]));
5059
5060   operands[3] = gen_rtx_REG (DImode, REGNO (operands[3]));
5061 })
5062
5063 (define_split
5064   [(set (match_operand:X87MODEF 0 "fp_register_operand")
5065         (float:X87MODEF (match_operand:DI 1 "memory_operand")))
5066    (clobber (match_scratch:V4SI 3))
5067    (clobber (match_scratch:V4SI 4))
5068    (clobber (match_operand:DI 2 "memory_operand"))]
5069   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5070    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC
5071    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5072    && reload_completed"
5073   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))])
5074
5075 (define_expand "floatuns<SWI12:mode><MODEF:mode>2"
5076   [(set (match_operand:MODEF 0 "register_operand")
5077         (unsigned_float:MODEF
5078           (match_operand:SWI12 1 "nonimmediate_operand")))]
5079   "!TARGET_64BIT
5080    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH"
5081 {
5082   operands[1] = convert_to_mode (SImode, operands[1], 1);
5083   emit_insn (gen_floatsi<MODEF:mode>2 (operands[0], operands[1]));
5084   DONE;
5085 })
5086
5087 ;; Avoid store forwarding (partial memory) stall penalty by extending
5088 ;; SImode value to DImode through XMM register instead of pushing two
5089 ;; SImode values to stack. Also note that fild loads from memory only.
5090
5091 (define_insn_and_split "*floatunssi<mode>2_i387_with_xmm"
5092   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
5093         (unsigned_float:X87MODEF
5094           (match_operand:SI 1 "nonimmediate_operand" "rm")))
5095    (clobber (match_scratch:DI 3 "=x"))
5096    (clobber (match_operand:DI 2 "memory_operand" "=m"))]
5097   "!TARGET_64BIT
5098    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5099    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC"
5100   "#"
5101   "&& reload_completed"
5102   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5103    (set (match_dup 2) (match_dup 3))
5104    (set (match_dup 0)
5105         (float:X87MODEF (match_dup 2)))]
5106   ""
5107   [(set_attr "type" "multi")
5108    (set_attr "mode" "<MODE>")])
5109
5110 (define_expand "floatunssi<mode>2"
5111   [(parallel
5112      [(set (match_operand:X87MODEF 0 "register_operand")
5113            (unsigned_float:X87MODEF
5114              (match_operand:SI 1 "nonimmediate_operand")))
5115       (clobber (match_scratch:DI 3))
5116       (clobber (match_dup 2))])]
5117   "!TARGET_64BIT
5118    && ((TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5119         && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC)
5120        || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
5121 {
5122   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5123     {
5124       ix86_expand_convert_uns_si<mode>_sse (operands[0], operands[1]);
5125       DONE;
5126     }
5127   else
5128     operands[2] = assign_386_stack_local (DImode, SLOT_TEMP);
5129 })
5130
5131 (define_expand "floatunsdisf2"
5132   [(use (match_operand:SF 0 "register_operand"))
5133    (use (match_operand:DI 1 "nonimmediate_operand"))]
5134   "TARGET_64BIT && TARGET_SSE_MATH"
5135   "x86_emit_floatuns (operands); DONE;")
5136
5137 (define_expand "floatunsdidf2"
5138   [(use (match_operand:DF 0 "register_operand"))
5139    (use (match_operand:DI 1 "nonimmediate_operand"))]
5140   "(TARGET_64BIT || TARGET_KEEPS_VECTOR_ALIGNED_STACK)
5141    && TARGET_SSE2 && TARGET_SSE_MATH"
5142 {
5143   if (TARGET_64BIT)
5144     x86_emit_floatuns (operands);
5145   else
5146     ix86_expand_convert_uns_didf_sse (operands[0], operands[1]);
5147   DONE;
5148 })
5149 \f
5150 ;; Load effective address instructions
5151
5152 (define_insn_and_split "*lea<mode>"
5153   [(set (match_operand:SWI48 0 "register_operand" "=r")
5154         (match_operand:SWI48 1 "address_no_seg_operand" "Ts"))]
5155   ""
5156 {
5157   if (SImode_address_operand (operands[1], VOIDmode))
5158     {
5159       gcc_assert (TARGET_64BIT);
5160       return "lea{l}\t{%E1, %k0|%k0, %E1}";
5161     }
5162   else 
5163     return "lea{<imodesuffix>}\t{%E1, %0|%0, %E1}";
5164 }
5165   "reload_completed && ix86_avoid_lea_for_addr (insn, operands)"
5166   [(const_int 0)]
5167 {
5168   machine_mode mode = <MODE>mode;
5169   rtx pat;
5170
5171   /* ix86_avoid_lea_for_addr re-recognizes insn and may
5172      change operands[] array behind our back.  */
5173   pat = PATTERN (curr_insn);
5174
5175   operands[0] = SET_DEST (pat);
5176   operands[1] = SET_SRC (pat);
5177
5178   /* Emit all operations in SImode for zero-extended addresses.  */
5179   if (SImode_address_operand (operands[1], VOIDmode))
5180     mode = SImode;
5181
5182   ix86_split_lea_for_addr (curr_insn, operands, mode);
5183
5184   /* Zero-extend return register to DImode for zero-extended addresses.  */
5185   if (mode != <MODE>mode)
5186     emit_insn (gen_zero_extendsidi2
5187                (operands[0], gen_lowpart (mode, operands[0])));
5188
5189   DONE;
5190 }
5191   [(set_attr "type" "lea")
5192    (set (attr "mode")
5193      (if_then_else
5194        (match_operand 1 "SImode_address_operand")
5195        (const_string "SI")
5196        (const_string "<MODE>")))])
5197 \f
5198 ;; Add instructions
5199
5200 (define_expand "add<mode>3"
5201   [(set (match_operand:SDWIM 0 "nonimmediate_operand")
5202         (plus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand")
5203                     (match_operand:SDWIM 2 "<general_operand>")))]
5204   ""
5205   "ix86_expand_binary_operator (PLUS, <MODE>mode, operands); DONE;")
5206
5207 (define_insn_and_split "*add<dwi>3_doubleword"
5208   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
5209         (plus:<DWI>
5210           (match_operand:<DWI> 1 "nonimmediate_operand" "%0,0")
5211           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
5212    (clobber (reg:CC FLAGS_REG))]
5213   "ix86_binary_operator_ok (PLUS, <DWI>mode, operands)"
5214   "#"
5215   "reload_completed"
5216   [(parallel [(set (reg:CC FLAGS_REG)
5217                    (unspec:CC [(match_dup 1) (match_dup 2)]
5218                               UNSPEC_ADD_CARRY))
5219               (set (match_dup 0)
5220                    (plus:DWIH (match_dup 1) (match_dup 2)))])
5221    (parallel [(set (match_dup 3)
5222                    (plus:DWIH
5223                      (match_dup 4)
5224                      (plus:DWIH
5225                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
5226                        (match_dup 5))))
5227               (clobber (reg:CC FLAGS_REG))])]
5228   "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
5229
5230 (define_insn "*add<mode>3_cc"
5231   [(set (reg:CC FLAGS_REG)
5232         (unspec:CC
5233           [(match_operand:SWI48 1 "nonimmediate_operand" "%0,0")
5234            (match_operand:SWI48 2 "<general_operand>" "r<i>,rm")]
5235           UNSPEC_ADD_CARRY))
5236    (set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
5237         (plus:SWI48 (match_dup 1) (match_dup 2)))]
5238   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5239   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
5240   [(set_attr "type" "alu")
5241    (set_attr "mode" "<MODE>")])
5242
5243 (define_insn "addqi3_cc"
5244   [(set (reg:CC FLAGS_REG)
5245         (unspec:CC
5246           [(match_operand:QI 1 "nonimmediate_operand" "%0,0")
5247            (match_operand:QI 2 "general_operand" "qn,qm")]
5248           UNSPEC_ADD_CARRY))
5249    (set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
5250         (plus:QI (match_dup 1) (match_dup 2)))]
5251   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5252   "add{b}\t{%2, %0|%0, %2}"
5253   [(set_attr "type" "alu")
5254    (set_attr "mode" "QI")])
5255
5256 (define_insn "*add<mode>_1"
5257   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm,r,r")
5258         (plus:SWI48
5259           (match_operand:SWI48 1 "nonimmediate_operand" "%0,0,r,r")
5260           (match_operand:SWI48 2 "x86_64_general_operand" "rme,re,0,le")))
5261    (clobber (reg:CC FLAGS_REG))]
5262   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5263 {
5264   switch (get_attr_type (insn))
5265     {
5266     case TYPE_LEA:
5267       return "#";
5268
5269     case TYPE_INCDEC:
5270       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5271       if (operands[2] == const1_rtx)
5272         return "inc{<imodesuffix>}\t%0";
5273       else
5274         {
5275           gcc_assert (operands[2] == constm1_rtx);
5276           return "dec{<imodesuffix>}\t%0";
5277         }
5278
5279     default:
5280       /* For most processors, ADD is faster than LEA.  This alternative
5281          was added to use ADD as much as possible.  */
5282       if (which_alternative == 2)
5283         std::swap (operands[1], operands[2]);
5284         
5285       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5286       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5287         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5288
5289       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5290     }
5291 }
5292   [(set (attr "type")
5293      (cond [(eq_attr "alternative" "3")
5294               (const_string "lea")
5295             (match_operand:SWI48 2 "incdec_operand")
5296               (const_string "incdec")
5297            ]
5298            (const_string "alu")))
5299    (set (attr "length_immediate")
5300       (if_then_else
5301         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5302         (const_string "1")
5303         (const_string "*")))
5304    (set_attr "mode" "<MODE>")])
5305
5306 ;; It may seem that nonimmediate operand is proper one for operand 1.
5307 ;; The addsi_1 pattern allows nonimmediate operand at that place and
5308 ;; we take care in ix86_binary_operator_ok to not allow two memory
5309 ;; operands so proper swapping will be done in reload.  This allow
5310 ;; patterns constructed from addsi_1 to match.
5311
5312 (define_insn "addsi_1_zext"
5313   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
5314         (zero_extend:DI
5315           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r,r")
5316                    (match_operand:SI 2 "x86_64_general_operand" "rme,0,le"))))
5317    (clobber (reg:CC FLAGS_REG))]
5318   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
5319 {
5320   switch (get_attr_type (insn))
5321     {
5322     case TYPE_LEA:
5323       return "#";
5324
5325     case TYPE_INCDEC:
5326       if (operands[2] == const1_rtx)
5327         return "inc{l}\t%k0";
5328       else
5329         {
5330           gcc_assert (operands[2] == constm1_rtx);
5331           return "dec{l}\t%k0";
5332         }
5333
5334     default:
5335       /* For most processors, ADD is faster than LEA.  This alternative
5336          was added to use ADD as much as possible.  */
5337       if (which_alternative == 1)
5338         std::swap (operands[1], operands[2]);
5339
5340       if (x86_maybe_negate_const_int (&operands[2], SImode))
5341         return "sub{l}\t{%2, %k0|%k0, %2}";
5342
5343       return "add{l}\t{%2, %k0|%k0, %2}";
5344     }
5345 }
5346   [(set (attr "type")
5347      (cond [(eq_attr "alternative" "2")
5348               (const_string "lea")
5349             (match_operand:SI 2 "incdec_operand")
5350               (const_string "incdec")
5351            ]
5352            (const_string "alu")))
5353    (set (attr "length_immediate")
5354       (if_then_else
5355         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5356         (const_string "1")
5357         (const_string "*")))
5358    (set_attr "mode" "SI")])
5359
5360 (define_insn "*addhi_1"
5361   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r,Yp")
5362         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,r,Yp")
5363                  (match_operand:HI 2 "general_operand" "rn,rm,0,ln")))
5364    (clobber (reg:CC FLAGS_REG))]
5365   "ix86_binary_operator_ok (PLUS, HImode, operands)"
5366 {
5367   switch (get_attr_type (insn))
5368     {
5369     case TYPE_LEA:
5370       return "#";
5371
5372     case TYPE_INCDEC:
5373       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5374       if (operands[2] == const1_rtx)
5375         return "inc{w}\t%0";
5376       else
5377         {
5378           gcc_assert (operands[2] == constm1_rtx);
5379           return "dec{w}\t%0";
5380         }
5381
5382     default:
5383       /* For most processors, ADD is faster than LEA.  This alternative
5384          was added to use ADD as much as possible.  */
5385       if (which_alternative == 2)
5386         std::swap (operands[1], operands[2]);
5387
5388       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5389       if (x86_maybe_negate_const_int (&operands[2], HImode))
5390         return "sub{w}\t{%2, %0|%0, %2}";
5391
5392       return "add{w}\t{%2, %0|%0, %2}";
5393     }
5394 }
5395   [(set (attr "type")
5396      (cond [(eq_attr "alternative" "3")
5397               (const_string "lea")
5398             (match_operand:HI 2 "incdec_operand")
5399               (const_string "incdec")
5400            ]
5401            (const_string "alu")))
5402    (set (attr "length_immediate")
5403       (if_then_else
5404         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5405         (const_string "1")
5406         (const_string "*")))
5407    (set_attr "mode" "HI,HI,HI,SI")])
5408
5409 ;; %%% Potential partial reg stall on alternatives 3 and 4.  What to do?
5410 (define_insn "*addqi_1"
5411   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,q,r,r,Yp")
5412         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,q,0,r,Yp")
5413                  (match_operand:QI 2 "general_operand" "qn,qm,0,rn,0,ln")))
5414    (clobber (reg:CC FLAGS_REG))]
5415   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5416 {
5417   bool widen = (which_alternative == 3 || which_alternative == 4);
5418
5419   switch (get_attr_type (insn))
5420     {
5421     case TYPE_LEA:
5422       return "#";
5423
5424     case TYPE_INCDEC:
5425       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5426       if (operands[2] == const1_rtx)
5427         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
5428       else
5429         {
5430           gcc_assert (operands[2] == constm1_rtx);
5431           return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
5432         }
5433
5434     default:
5435       /* For most processors, ADD is faster than LEA.  These alternatives
5436          were added to use ADD as much as possible.  */
5437       if (which_alternative == 2 || which_alternative == 4)
5438         std::swap (operands[1], operands[2]);
5439
5440       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5441       if (x86_maybe_negate_const_int (&operands[2], QImode))
5442         {
5443           if (widen)
5444             return "sub{l}\t{%2, %k0|%k0, %2}";
5445           else
5446             return "sub{b}\t{%2, %0|%0, %2}";
5447         }
5448       if (widen)
5449         return "add{l}\t{%k2, %k0|%k0, %k2}";
5450       else
5451         return "add{b}\t{%2, %0|%0, %2}";
5452     }
5453 }
5454   [(set (attr "type")
5455      (cond [(eq_attr "alternative" "5")
5456               (const_string "lea")
5457             (match_operand:QI 2 "incdec_operand")
5458               (const_string "incdec")
5459            ]
5460            (const_string "alu")))
5461    (set (attr "length_immediate")
5462       (if_then_else
5463         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5464         (const_string "1")
5465         (const_string "*")))
5466    (set_attr "mode" "QI,QI,QI,SI,SI,SI")])
5467
5468 (define_insn "*addqi_1_slp"
5469   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
5470         (plus:QI (match_dup 0)
5471                  (match_operand:QI 1 "general_operand" "qn,qm")))
5472    (clobber (reg:CC FLAGS_REG))]
5473   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
5474    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
5475 {
5476   switch (get_attr_type (insn))
5477     {
5478     case TYPE_INCDEC:
5479       if (operands[1] == const1_rtx)
5480         return "inc{b}\t%0";
5481       else
5482         {
5483           gcc_assert (operands[1] == constm1_rtx);
5484           return "dec{b}\t%0";
5485         }
5486
5487     default:
5488       if (x86_maybe_negate_const_int (&operands[1], QImode))
5489         return "sub{b}\t{%1, %0|%0, %1}";
5490
5491       return "add{b}\t{%1, %0|%0, %1}";
5492     }
5493 }
5494   [(set (attr "type")
5495      (if_then_else (match_operand:QI 1 "incdec_operand")
5496         (const_string "incdec")
5497         (const_string "alu1")))
5498    (set (attr "memory")
5499      (if_then_else (match_operand 1 "memory_operand")
5500         (const_string "load")
5501         (const_string "none")))
5502    (set_attr "mode" "QI")])
5503
5504 ;; Split non destructive adds if we cannot use lea.
5505 (define_split
5506   [(set (match_operand:SWI48 0 "register_operand")
5507         (plus:SWI48 (match_operand:SWI48 1 "register_operand")
5508                     (match_operand:SWI48 2 "x86_64_nonmemory_operand")))
5509    (clobber (reg:CC FLAGS_REG))]
5510   "reload_completed && ix86_avoid_lea_for_add (insn, operands)"
5511   [(set (match_dup 0) (match_dup 1))
5512    (parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (match_dup 2)))
5513               (clobber (reg:CC FLAGS_REG))])])
5514
5515 ;; Convert add to the lea pattern to avoid flags dependency.
5516 (define_split
5517   [(set (match_operand:SWI 0 "register_operand")
5518         (plus:SWI (match_operand:SWI 1 "register_operand")
5519                   (match_operand:SWI 2 "<nonmemory_operand>")))
5520    (clobber (reg:CC FLAGS_REG))]
5521   "reload_completed && ix86_lea_for_add_ok (insn, operands)" 
5522   [(const_int 0)]
5523 {
5524   machine_mode mode = <MODE>mode;
5525   rtx pat;
5526
5527   if (<MODE_SIZE> < GET_MODE_SIZE (SImode))
5528     { 
5529       mode = SImode; 
5530       operands[0] = gen_lowpart (mode, operands[0]);
5531       operands[1] = gen_lowpart (mode, operands[1]);
5532       operands[2] = gen_lowpart (mode, operands[2]);
5533     }
5534
5535   pat = gen_rtx_PLUS (mode, operands[1], operands[2]);
5536
5537   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5538   DONE;
5539 })
5540
5541 ;; Split non destructive adds if we cannot use lea.
5542 (define_split
5543   [(set (match_operand:DI 0 "register_operand")
5544         (zero_extend:DI
5545           (plus:SI (match_operand:SI 1 "register_operand")
5546                    (match_operand:SI 2 "x86_64_nonmemory_operand"))))
5547    (clobber (reg:CC FLAGS_REG))]
5548   "TARGET_64BIT
5549    && reload_completed && ix86_avoid_lea_for_add (insn, operands)"
5550   [(set (match_dup 3) (match_dup 1))
5551    (parallel [(set (match_dup 0)
5552                    (zero_extend:DI (plus:SI (match_dup 3) (match_dup 2))))
5553               (clobber (reg:CC FLAGS_REG))])]
5554   "operands[3] = gen_lowpart (SImode, operands[0]);")
5555
5556 ;; Convert add to the lea pattern to avoid flags dependency.
5557 (define_split
5558   [(set (match_operand:DI 0 "register_operand")
5559         (zero_extend:DI
5560           (plus:SI (match_operand:SI 1 "register_operand")
5561                    (match_operand:SI 2 "x86_64_nonmemory_operand"))))
5562    (clobber (reg:CC FLAGS_REG))]
5563   "TARGET_64BIT && reload_completed && ix86_lea_for_add_ok (insn, operands)"
5564   [(set (match_dup 0)
5565         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))])
5566
5567 (define_insn "*add<mode>_2"
5568   [(set (reg FLAGS_REG)
5569         (compare
5570           (plus:SWI
5571             (match_operand:SWI 1 "nonimmediate_operand" "%0,0,<r>")
5572             (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>,0"))
5573           (const_int 0)))
5574    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m,<r>")
5575         (plus:SWI (match_dup 1) (match_dup 2)))]
5576   "ix86_match_ccmode (insn, CCGOCmode)
5577    && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5578 {
5579   switch (get_attr_type (insn))
5580     {
5581     case TYPE_INCDEC:
5582       if (operands[2] == const1_rtx)
5583         return "inc{<imodesuffix>}\t%0";
5584       else
5585         {
5586           gcc_assert (operands[2] == constm1_rtx);
5587           return "dec{<imodesuffix>}\t%0";
5588         }
5589
5590     default:
5591       if (which_alternative == 2)
5592         std::swap (operands[1], operands[2]);
5593         
5594       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5595       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5596         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5597
5598       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5599     }
5600 }
5601   [(set (attr "type")
5602      (if_then_else (match_operand:SWI 2 "incdec_operand")
5603         (const_string "incdec")
5604         (const_string "alu")))
5605    (set (attr "length_immediate")
5606       (if_then_else
5607         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5608         (const_string "1")
5609         (const_string "*")))
5610    (set_attr "mode" "<MODE>")])
5611
5612 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
5613 (define_insn "*addsi_2_zext"
5614   [(set (reg FLAGS_REG)
5615         (compare
5616           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r")
5617                    (match_operand:SI 2 "x86_64_general_operand" "rme,0"))
5618           (const_int 0)))
5619    (set (match_operand:DI 0 "register_operand" "=r,r")
5620         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
5621   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
5622    && ix86_binary_operator_ok (PLUS, SImode, operands)"
5623 {
5624   switch (get_attr_type (insn))
5625     {
5626     case TYPE_INCDEC:
5627       if (operands[2] == const1_rtx)
5628         return "inc{l}\t%k0";
5629       else
5630         {
5631           gcc_assert (operands[2] == constm1_rtx);
5632           return "dec{l}\t%k0";
5633         }
5634
5635     default:
5636       if (which_alternative == 1)
5637         std::swap (operands[1], operands[2]);
5638
5639       if (x86_maybe_negate_const_int (&operands[2], SImode))
5640         return "sub{l}\t{%2, %k0|%k0, %2}";
5641
5642       return "add{l}\t{%2, %k0|%k0, %2}";
5643     }
5644 }
5645   [(set (attr "type")
5646      (if_then_else (match_operand:SI 2 "incdec_operand")
5647         (const_string "incdec")
5648         (const_string "alu")))
5649    (set (attr "length_immediate")
5650       (if_then_else
5651         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5652         (const_string "1")
5653         (const_string "*")))
5654    (set_attr "mode" "SI")])
5655
5656 (define_insn "*add<mode>_3"
5657   [(set (reg FLAGS_REG)
5658         (compare
5659           (neg:SWI (match_operand:SWI 2 "<general_operand>" "<g>,0"))
5660           (match_operand:SWI 1 "nonimmediate_operand" "%0,<r>")))
5661    (clobber (match_scratch:SWI 0 "=<r>,<r>"))]
5662   "ix86_match_ccmode (insn, CCZmode)
5663    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
5664 {
5665   switch (get_attr_type (insn))
5666     {
5667     case TYPE_INCDEC:
5668       if (operands[2] == const1_rtx)
5669         return "inc{<imodesuffix>}\t%0";
5670       else
5671         {
5672           gcc_assert (operands[2] == constm1_rtx);
5673           return "dec{<imodesuffix>}\t%0";
5674         }
5675
5676     default:
5677       if (which_alternative == 1)
5678         std::swap (operands[1], operands[2]);
5679
5680       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5681       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5682         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5683
5684       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5685     }
5686 }
5687   [(set (attr "type")
5688      (if_then_else (match_operand:SWI 2 "incdec_operand")
5689         (const_string "incdec")
5690         (const_string "alu")))
5691    (set (attr "length_immediate")
5692       (if_then_else
5693         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5694         (const_string "1")
5695         (const_string "*")))
5696    (set_attr "mode" "<MODE>")])
5697
5698 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
5699 (define_insn "*addsi_3_zext"
5700   [(set (reg FLAGS_REG)
5701         (compare
5702           (neg:SI (match_operand:SI 2 "x86_64_general_operand" "rme,0"))
5703           (match_operand:SI 1 "nonimmediate_operand" "%0,r")))
5704    (set (match_operand:DI 0 "register_operand" "=r,r")
5705         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
5706   "TARGET_64BIT && ix86_match_ccmode (insn, CCZmode)
5707    && ix86_binary_operator_ok (PLUS, SImode, operands)"
5708 {
5709   switch (get_attr_type (insn))
5710     {
5711     case TYPE_INCDEC:
5712       if (operands[2] == const1_rtx)
5713         return "inc{l}\t%k0";
5714       else
5715         {
5716           gcc_assert (operands[2] == constm1_rtx);
5717           return "dec{l}\t%k0";
5718         }
5719
5720     default:
5721       if (which_alternative == 1)
5722         std::swap (operands[1], operands[2]);
5723
5724       if (x86_maybe_negate_const_int (&operands[2], SImode))
5725         return "sub{l}\t{%2, %k0|%k0, %2}";
5726
5727       return "add{l}\t{%2, %k0|%k0, %2}";
5728     }
5729 }
5730   [(set (attr "type")
5731      (if_then_else (match_operand:SI 2 "incdec_operand")
5732         (const_string "incdec")
5733         (const_string "alu")))
5734    (set (attr "length_immediate")
5735       (if_then_else
5736         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5737         (const_string "1")
5738         (const_string "*")))
5739    (set_attr "mode" "SI")])
5740
5741 ; For comparisons against 1, -1 and 128, we may generate better code
5742 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
5743 ; is matched then.  We can't accept general immediate, because for
5744 ; case of overflows,  the result is messed up.
5745 ; Also carry flag is reversed compared to cmp, so this conversion is valid
5746 ; only for comparisons not depending on it.
5747
5748 (define_insn "*adddi_4"
5749   [(set (reg FLAGS_REG)
5750         (compare
5751           (match_operand:DI 1 "nonimmediate_operand" "0")
5752           (match_operand:DI 2 "x86_64_immediate_operand" "e")))
5753    (clobber (match_scratch:DI 0 "=rm"))]
5754   "TARGET_64BIT
5755    && ix86_match_ccmode (insn, CCGCmode)"
5756 {
5757   switch (get_attr_type (insn))
5758     {
5759     case TYPE_INCDEC:
5760       if (operands[2] == constm1_rtx)
5761         return "inc{q}\t%0";
5762       else
5763         {
5764           gcc_assert (operands[2] == const1_rtx);
5765           return "dec{q}\t%0";
5766         }
5767
5768     default:
5769       if (x86_maybe_negate_const_int (&operands[2], DImode))
5770         return "add{q}\t{%2, %0|%0, %2}";
5771
5772       return "sub{q}\t{%2, %0|%0, %2}";
5773     }
5774 }
5775   [(set (attr "type")
5776      (if_then_else (match_operand:DI 2 "incdec_operand")
5777         (const_string "incdec")
5778         (const_string "alu")))
5779    (set (attr "length_immediate")
5780       (if_then_else
5781         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5782         (const_string "1")
5783         (const_string "*")))
5784    (set_attr "mode" "DI")])
5785
5786 ; For comparisons against 1, -1 and 128, we may generate better code
5787 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
5788 ; is matched then.  We can't accept general immediate, because for
5789 ; case of overflows,  the result is messed up.
5790 ; Also carry flag is reversed compared to cmp, so this conversion is valid
5791 ; only for comparisons not depending on it.
5792
5793 (define_insn "*add<mode>_4"
5794   [(set (reg FLAGS_REG)
5795         (compare
5796           (match_operand:SWI124 1 "nonimmediate_operand" "0")
5797           (match_operand:SWI124 2 "const_int_operand" "n")))
5798    (clobber (match_scratch:SWI124 0 "=<r>m"))]
5799   "ix86_match_ccmode (insn, CCGCmode)"
5800 {
5801   switch (get_attr_type (insn))
5802     {
5803     case TYPE_INCDEC:
5804       if (operands[2] == constm1_rtx)
5805         return "inc{<imodesuffix>}\t%0";
5806       else
5807         {
5808           gcc_assert (operands[2] == const1_rtx);
5809           return "dec{<imodesuffix>}\t%0";
5810         }
5811
5812     default:
5813       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5814         return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5815
5816       return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5817     }
5818 }
5819   [(set (attr "type")
5820      (if_then_else (match_operand:<MODE> 2 "incdec_operand")
5821         (const_string "incdec")
5822         (const_string "alu")))
5823    (set (attr "length_immediate")
5824       (if_then_else
5825         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5826         (const_string "1")
5827         (const_string "*")))
5828    (set_attr "mode" "<MODE>")])
5829
5830 (define_insn "*add<mode>_5"
5831   [(set (reg FLAGS_REG)
5832         (compare
5833           (plus:SWI
5834             (match_operand:SWI 1 "nonimmediate_operand" "%0,<r>")
5835             (match_operand:SWI 2 "<general_operand>" "<g>,0"))
5836           (const_int 0)))
5837    (clobber (match_scratch:SWI 0 "=<r>,<r>"))]
5838   "ix86_match_ccmode (insn, CCGOCmode)
5839    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
5840 {
5841   switch (get_attr_type (insn))
5842     {
5843     case TYPE_INCDEC:
5844       if (operands[2] == const1_rtx)
5845         return "inc{<imodesuffix>}\t%0";
5846       else
5847         {
5848           gcc_assert (operands[2] == constm1_rtx);
5849           return "dec{<imodesuffix>}\t%0";
5850         }
5851
5852     default:
5853       if (which_alternative == 1)
5854         std::swap (operands[1], operands[2]);
5855
5856       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5857       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5858         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5859
5860       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5861     }
5862 }
5863   [(set (attr "type")
5864      (if_then_else (match_operand:SWI 2 "incdec_operand")
5865         (const_string "incdec")
5866         (const_string "alu")))
5867    (set (attr "length_immediate")
5868       (if_then_else
5869         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5870         (const_string "1")
5871         (const_string "*")))
5872    (set_attr "mode" "<MODE>")])
5873
5874 (define_insn "addqi_ext_1"
5875   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
5876                          (const_int 8)
5877                          (const_int 8))
5878         (plus:SI
5879           (zero_extract:SI
5880             (match_operand 1 "ext_register_operand" "0,0")
5881             (const_int 8)
5882             (const_int 8))
5883           (match_operand:QI 2 "general_x64nomem_operand" "Qn,m")))
5884    (clobber (reg:CC FLAGS_REG))]
5885   ""
5886 {
5887   switch (get_attr_type (insn))
5888     {
5889     case TYPE_INCDEC:
5890       if (operands[2] == const1_rtx)
5891         return "inc{b}\t%h0";
5892       else
5893         {
5894           gcc_assert (operands[2] == constm1_rtx);
5895           return "dec{b}\t%h0";
5896         }
5897
5898     default:
5899       return "add{b}\t{%2, %h0|%h0, %2}";
5900     }
5901 }
5902   [(set_attr "isa" "*,nox64")
5903    (set (attr "type")
5904      (if_then_else (match_operand:QI 2 "incdec_operand")
5905         (const_string "incdec")
5906         (const_string "alu")))
5907    (set_attr "modrm" "1")
5908    (set_attr "mode" "QI")])
5909
5910 (define_insn "*addqi_ext_2"
5911   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
5912                          (const_int 8)
5913                          (const_int 8))
5914         (plus:SI
5915           (zero_extract:SI
5916             (match_operand 1 "ext_register_operand" "%0")
5917             (const_int 8)
5918             (const_int 8))
5919           (zero_extract:SI
5920             (match_operand 2 "ext_register_operand" "Q")
5921             (const_int 8)
5922             (const_int 8))))
5923    (clobber (reg:CC FLAGS_REG))]
5924   ""
5925   "add{b}\t{%h2, %h0|%h0, %h2}"
5926   [(set_attr "type" "alu")
5927    (set_attr "mode" "QI")])
5928
5929 ;; Add with jump on overflow.
5930 (define_expand "addv<mode>4"
5931   [(parallel [(set (reg:CCO FLAGS_REG)
5932                    (eq:CCO (plus:<DWI>
5933                               (sign_extend:<DWI>
5934                                  (match_operand:SWI 1 "nonimmediate_operand"))
5935                               (match_dup 4))
5936                            (sign_extend:<DWI>
5937                               (plus:SWI (match_dup 1)
5938                                         (match_operand:SWI 2
5939                                            "<general_operand>")))))
5940               (set (match_operand:SWI 0 "register_operand")
5941                    (plus:SWI (match_dup 1) (match_dup 2)))])
5942    (set (pc) (if_then_else
5943                (eq (reg:CCO FLAGS_REG) (const_int 0))
5944                (label_ref (match_operand 3))
5945                (pc)))]
5946   ""
5947 {
5948   ix86_fixup_binary_operands_no_copy (PLUS, <MODE>mode, operands);
5949   if (CONST_INT_P (operands[2]))
5950     operands[4] = operands[2];
5951   else
5952     operands[4] = gen_rtx_SIGN_EXTEND (<DWI>mode, operands[2]);
5953 })
5954
5955 (define_insn "*addv<mode>4"
5956   [(set (reg:CCO FLAGS_REG)
5957         (eq:CCO (plus:<DWI>
5958                    (sign_extend:<DWI>
5959                       (match_operand:SWI 1 "nonimmediate_operand" "%0,0"))
5960                    (sign_extend:<DWI>
5961                       (match_operand:SWI 2 "<general_sext_operand>"
5962                                            "<r>mWe,<r>We")))
5963                 (sign_extend:<DWI>
5964                    (plus:SWI (match_dup 1) (match_dup 2)))))
5965    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
5966         (plus:SWI (match_dup 1) (match_dup 2)))]
5967   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5968   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
5969   [(set_attr "type" "alu")
5970    (set_attr "mode" "<MODE>")])
5971
5972 (define_insn "*addv<mode>4_1"
5973   [(set (reg:CCO FLAGS_REG)
5974         (eq:CCO (plus:<DWI>
5975                    (sign_extend:<DWI>
5976                       (match_operand:SWI 1 "nonimmediate_operand" "0"))
5977                    (match_operand:<DWI> 3 "const_int_operand" "i"))
5978                 (sign_extend:<DWI>
5979                    (plus:SWI (match_dup 1)
5980                              (match_operand:SWI 2 "x86_64_immediate_operand"
5981                                                   "<i>")))))
5982    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
5983         (plus:SWI (match_dup 1) (match_dup 2)))]
5984   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)
5985    && CONST_INT_P (operands[2])
5986    && INTVAL (operands[2]) == INTVAL (operands[3])"
5987   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
5988   [(set_attr "type" "alu")
5989    (set_attr "mode" "<MODE>")
5990    (set (attr "length_immediate")
5991         (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
5992                   (const_string "1")
5993                (match_test "<MODE_SIZE> == 8")
5994                   (const_string "4")]
5995               (const_string "<MODE_SIZE>")))])
5996
5997 ;; The lea patterns for modes less than 32 bits need to be matched by
5998 ;; several insns converted to real lea by splitters.
5999
6000 (define_insn_and_split "*lea_general_1"
6001   [(set (match_operand 0 "register_operand" "=r")
6002         (plus (plus (match_operand 1 "index_register_operand" "l")
6003                     (match_operand 2 "register_operand" "r"))
6004               (match_operand 3 "immediate_operand" "i")))]
6005   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6006    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6007    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6008    && GET_MODE (operands[0]) == GET_MODE (operands[2])
6009    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
6010        || GET_MODE (operands[3]) == VOIDmode)"
6011   "#"
6012   "&& reload_completed"
6013   [(const_int 0)]
6014 {
6015   machine_mode mode = SImode;
6016   rtx pat;
6017
6018   operands[0] = gen_lowpart (mode, operands[0]);
6019   operands[1] = gen_lowpart (mode, operands[1]);
6020   operands[2] = gen_lowpart (mode, operands[2]);
6021   operands[3] = gen_lowpart (mode, operands[3]);
6022
6023   pat = gen_rtx_PLUS (mode, gen_rtx_PLUS (mode, operands[1], operands[2]),
6024                       operands[3]);
6025
6026   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6027   DONE;
6028 }
6029   [(set_attr "type" "lea")
6030    (set_attr "mode" "SI")])
6031
6032 (define_insn_and_split "*lea_general_2"
6033   [(set (match_operand 0 "register_operand" "=r")
6034         (plus (mult (match_operand 1 "index_register_operand" "l")
6035                     (match_operand 2 "const248_operand" "n"))
6036               (match_operand 3 "nonmemory_operand" "ri")))]
6037   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6038    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6039    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6040    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
6041        || GET_MODE (operands[3]) == VOIDmode)"
6042   "#"
6043   "&& reload_completed"
6044   [(const_int 0)]
6045 {
6046   machine_mode mode = SImode;
6047   rtx pat;
6048
6049   operands[0] = gen_lowpart (mode, operands[0]);
6050   operands[1] = gen_lowpart (mode, operands[1]);
6051   operands[3] = gen_lowpart (mode, operands[3]);
6052
6053   pat = gen_rtx_PLUS (mode, gen_rtx_MULT (mode, operands[1], operands[2]),
6054                       operands[3]);
6055
6056   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6057   DONE;
6058 }
6059   [(set_attr "type" "lea")
6060    (set_attr "mode" "SI")])
6061
6062 (define_insn_and_split "*lea_general_3"
6063   [(set (match_operand 0 "register_operand" "=r")
6064         (plus (plus (mult (match_operand 1 "index_register_operand" "l")
6065                           (match_operand 2 "const248_operand" "n"))
6066                     (match_operand 3 "register_operand" "r"))
6067               (match_operand 4 "immediate_operand" "i")))]
6068   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6069    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6070    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6071    && GET_MODE (operands[0]) == GET_MODE (operands[3])"
6072   "#"
6073   "&& reload_completed"
6074   [(const_int 0)]
6075 {
6076   machine_mode mode = SImode;
6077   rtx pat;
6078
6079   operands[0] = gen_lowpart (mode, operands[0]);
6080   operands[1] = gen_lowpart (mode, operands[1]);
6081   operands[3] = gen_lowpart (mode, operands[3]);
6082   operands[4] = gen_lowpart (mode, operands[4]);
6083
6084   pat = gen_rtx_PLUS (mode,
6085                       gen_rtx_PLUS (mode,
6086                                     gen_rtx_MULT (mode, operands[1],
6087                                                         operands[2]),
6088                                     operands[3]),
6089                       operands[4]);
6090
6091   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6092   DONE;
6093 }
6094   [(set_attr "type" "lea")
6095    (set_attr "mode" "SI")])
6096
6097 (define_insn_and_split "*lea_general_4"
6098   [(set (match_operand 0 "register_operand" "=r")
6099         (any_or (ashift
6100                   (match_operand 1 "index_register_operand" "l")
6101                   (match_operand 2 "const_int_operand" "n"))
6102                 (match_operand 3 "const_int_operand" "n")))]
6103   "(((GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6104       && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)))
6105     || GET_MODE (operands[0]) == SImode
6106     || (TARGET_64BIT && GET_MODE (operands[0]) == DImode))
6107    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6108    && ((unsigned HOST_WIDE_INT) INTVAL (operands[2])) - 1 < 3
6109    && ((unsigned HOST_WIDE_INT) INTVAL (operands[3])
6110        < ((unsigned HOST_WIDE_INT) 1 << INTVAL (operands[2])))"
6111   "#"
6112   "&& reload_completed"
6113   [(const_int 0)]
6114 {
6115   machine_mode mode = GET_MODE (operands[0]);
6116   rtx pat;
6117
6118   if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
6119     { 
6120       mode = SImode; 
6121       operands[0] = gen_lowpart (mode, operands[0]);
6122       operands[1] = gen_lowpart (mode, operands[1]);
6123     }
6124
6125   operands[2] = GEN_INT (1 << INTVAL (operands[2]));
6126
6127   pat = plus_constant (mode, gen_rtx_MULT (mode, operands[1], operands[2]),
6128                        INTVAL (operands[3]));
6129
6130   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6131   DONE;
6132 }
6133   [(set_attr "type" "lea")
6134    (set (attr "mode")
6135       (if_then_else (match_operand:DI 0)
6136         (const_string "DI")
6137         (const_string "SI")))])
6138 \f
6139 ;; Subtract instructions
6140
6141 (define_expand "sub<mode>3"
6142   [(set (match_operand:SDWIM 0 "nonimmediate_operand")
6143         (minus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand")
6144                      (match_operand:SDWIM 2 "<general_operand>")))]
6145   ""
6146   "ix86_expand_binary_operator (MINUS, <MODE>mode, operands); DONE;")
6147
6148 (define_insn_and_split "*sub<dwi>3_doubleword"
6149   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
6150         (minus:<DWI>
6151           (match_operand:<DWI> 1 "nonimmediate_operand" "0,0")
6152           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
6153    (clobber (reg:CC FLAGS_REG))]
6154   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6155   "#"
6156   "reload_completed"
6157   [(parallel [(set (reg:CC FLAGS_REG)
6158                    (compare:CC (match_dup 1) (match_dup 2)))
6159               (set (match_dup 0)
6160                    (minus:DWIH (match_dup 1) (match_dup 2)))])
6161    (parallel [(set (match_dup 3)
6162                    (minus:DWIH
6163                      (match_dup 4)
6164                      (plus:DWIH
6165                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
6166                        (match_dup 5))))
6167               (clobber (reg:CC FLAGS_REG))])]
6168   "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
6169
6170 (define_insn "*sub<mode>_1"
6171   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6172         (minus:SWI
6173           (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6174           (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
6175    (clobber (reg:CC FLAGS_REG))]
6176   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6177   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6178   [(set_attr "type" "alu")
6179    (set_attr "mode" "<MODE>")])
6180
6181 (define_insn "*subsi_1_zext"
6182   [(set (match_operand:DI 0 "register_operand" "=r")
6183         (zero_extend:DI
6184           (minus:SI (match_operand:SI 1 "register_operand" "0")
6185                     (match_operand:SI 2 "x86_64_general_operand" "rme"))))
6186    (clobber (reg:CC FLAGS_REG))]
6187   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6188   "sub{l}\t{%2, %k0|%k0, %2}"
6189   [(set_attr "type" "alu")
6190    (set_attr "mode" "SI")])
6191
6192 (define_insn "*subqi_1_slp"
6193   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
6194         (minus:QI (match_dup 0)
6195                   (match_operand:QI 1 "general_operand" "qn,qm")))
6196    (clobber (reg:CC FLAGS_REG))]
6197   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6198    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6199   "sub{b}\t{%1, %0|%0, %1}"
6200   [(set_attr "type" "alu1")
6201    (set_attr "mode" "QI")])
6202
6203 (define_insn "*sub<mode>_2"
6204   [(set (reg FLAGS_REG)
6205         (compare
6206           (minus:SWI
6207             (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6208             (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
6209           (const_int 0)))
6210    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6211         (minus:SWI (match_dup 1) (match_dup 2)))]
6212   "ix86_match_ccmode (insn, CCGOCmode)
6213    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6214   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6215   [(set_attr "type" "alu")
6216    (set_attr "mode" "<MODE>")])
6217
6218 (define_insn "*subsi_2_zext"
6219   [(set (reg FLAGS_REG)
6220         (compare
6221           (minus:SI (match_operand:SI 1 "register_operand" "0")
6222                     (match_operand:SI 2 "x86_64_general_operand" "rme"))
6223           (const_int 0)))
6224    (set (match_operand:DI 0 "register_operand" "=r")
6225         (zero_extend:DI
6226           (minus:SI (match_dup 1)
6227                     (match_dup 2))))]
6228   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6229    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6230   "sub{l}\t{%2, %k0|%k0, %2}"
6231   [(set_attr "type" "alu")
6232    (set_attr "mode" "SI")])
6233
6234 ;; Subtract with jump on overflow.
6235 (define_expand "subv<mode>4"
6236   [(parallel [(set (reg:CCO FLAGS_REG)
6237                    (eq:CCO (minus:<DWI>
6238                               (sign_extend:<DWI>
6239                                  (match_operand:SWI 1 "nonimmediate_operand"))
6240                               (match_dup 4))
6241                            (sign_extend:<DWI>
6242                               (minus:SWI (match_dup 1)
6243                                          (match_operand:SWI 2
6244                                             "<general_operand>")))))
6245               (set (match_operand:SWI 0 "register_operand")
6246                    (minus:SWI (match_dup 1) (match_dup 2)))])
6247    (set (pc) (if_then_else
6248                (eq (reg:CCO FLAGS_REG) (const_int 0))
6249                (label_ref (match_operand 3))
6250                (pc)))]
6251   ""
6252 {
6253   ix86_fixup_binary_operands_no_copy (MINUS, <MODE>mode, operands);
6254   if (CONST_INT_P (operands[2]))
6255     operands[4] = operands[2];
6256   else
6257     operands[4] = gen_rtx_SIGN_EXTEND (<DWI>mode, operands[2]);
6258 })
6259
6260 (define_insn "*subv<mode>4"
6261   [(set (reg:CCO FLAGS_REG)
6262         (eq:CCO (minus:<DWI>
6263                    (sign_extend:<DWI>
6264                       (match_operand:SWI 1 "nonimmediate_operand" "0,0"))
6265                    (sign_extend:<DWI>
6266                       (match_operand:SWI 2 "<general_sext_operand>"
6267                                            "<r>We,<r>m")))
6268                 (sign_extend:<DWI>
6269                    (minus:SWI (match_dup 1) (match_dup 2)))))
6270    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6271         (minus:SWI (match_dup 1) (match_dup 2)))]
6272   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6273   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6274   [(set_attr "type" "alu")
6275    (set_attr "mode" "<MODE>")])
6276
6277 (define_insn "*subv<mode>4_1"
6278   [(set (reg:CCO FLAGS_REG)
6279         (eq:CCO (minus:<DWI>
6280                    (sign_extend:<DWI>
6281                       (match_operand:SWI 1 "nonimmediate_operand" "0"))
6282                    (match_operand:<DWI> 3 "const_int_operand" "i"))
6283                 (sign_extend:<DWI>
6284                    (minus:SWI (match_dup 1)
6285                               (match_operand:SWI 2 "x86_64_immediate_operand"
6286                                                    "<i>")))))
6287    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
6288         (minus:SWI (match_dup 1) (match_dup 2)))]
6289   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)
6290    && CONST_INT_P (operands[2])
6291    && INTVAL (operands[2]) == INTVAL (operands[3])"
6292   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6293   [(set_attr "type" "alu")
6294    (set_attr "mode" "<MODE>")
6295    (set (attr "length_immediate")
6296         (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
6297                   (const_string "1")
6298                (match_test "<MODE_SIZE> == 8")
6299                   (const_string "4")]
6300               (const_string "<MODE_SIZE>")))])
6301
6302 (define_insn "*sub<mode>_3"
6303   [(set (reg FLAGS_REG)
6304         (compare (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6305                  (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
6306    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6307         (minus:SWI (match_dup 1) (match_dup 2)))]
6308   "ix86_match_ccmode (insn, CCmode)
6309    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6310   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6311   [(set_attr "type" "alu")
6312    (set_attr "mode" "<MODE>")])
6313
6314 (define_insn "*subsi_3_zext"
6315   [(set (reg FLAGS_REG)
6316         (compare (match_operand:SI 1 "register_operand" "0")
6317                  (match_operand:SI 2 "x86_64_general_operand" "rme")))
6318    (set (match_operand:DI 0 "register_operand" "=r")
6319         (zero_extend:DI
6320           (minus:SI (match_dup 1)
6321                     (match_dup 2))))]
6322   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
6323    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6324   "sub{l}\t{%2, %1|%1, %2}"
6325   [(set_attr "type" "alu")
6326    (set_attr "mode" "SI")])
6327 \f
6328 ;; Add with carry and subtract with borrow
6329
6330 (define_expand "<plusminus_insn><mode>3_carry"
6331   [(parallel
6332     [(set (match_operand:SWI 0 "nonimmediate_operand")
6333           (plusminus:SWI
6334             (match_operand:SWI 1 "nonimmediate_operand")
6335             (plus:SWI (match_operator:SWI 4 "ix86_carry_flag_operator"
6336                        [(match_operand 3 "flags_reg_operand")
6337                         (const_int 0)])
6338                       (match_operand:SWI 2 "<general_operand>"))))
6339      (clobber (reg:CC FLAGS_REG))])]
6340   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)")
6341
6342 (define_insn "*<plusminus_insn><mode>3_carry"
6343   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6344         (plusminus:SWI
6345           (match_operand:SWI 1 "nonimmediate_operand" "<comm>0,0")
6346           (plus:SWI
6347             (match_operator 3 "ix86_carry_flag_operator"
6348              [(reg FLAGS_REG) (const_int 0)])
6349             (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))))
6350    (clobber (reg:CC FLAGS_REG))]
6351   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6352   "<plusminus_carry_mnemonic>{<imodesuffix>}\t{%2, %0|%0, %2}"
6353   [(set_attr "type" "alu")
6354    (set_attr "use_carry" "1")
6355    (set_attr "pent_pair" "pu")
6356    (set_attr "mode" "<MODE>")])
6357
6358 (define_insn "*addsi3_carry_zext"
6359   [(set (match_operand:DI 0 "register_operand" "=r")
6360         (zero_extend:DI
6361           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6362                    (plus:SI (match_operator 3 "ix86_carry_flag_operator"
6363                              [(reg FLAGS_REG) (const_int 0)])
6364                             (match_operand:SI 2 "x86_64_general_operand" "rme")))))
6365    (clobber (reg:CC FLAGS_REG))]
6366   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
6367   "adc{l}\t{%2, %k0|%k0, %2}"
6368   [(set_attr "type" "alu")
6369    (set_attr "use_carry" "1")
6370    (set_attr "pent_pair" "pu")
6371    (set_attr "mode" "SI")])
6372
6373 (define_insn "*subsi3_carry_zext"
6374   [(set (match_operand:DI 0 "register_operand" "=r")
6375         (zero_extend:DI
6376           (minus:SI (match_operand:SI 1 "register_operand" "0")
6377                     (plus:SI (match_operator 3 "ix86_carry_flag_operator"
6378                               [(reg FLAGS_REG) (const_int 0)])
6379                              (match_operand:SI 2 "x86_64_general_operand" "rme")))))
6380    (clobber (reg:CC FLAGS_REG))]
6381   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6382   "sbb{l}\t{%2, %k0|%k0, %2}"
6383   [(set_attr "type" "alu")
6384    (set_attr "pent_pair" "pu")
6385    (set_attr "mode" "SI")])
6386 \f
6387 ;; ADCX instruction
6388
6389 (define_insn "adcx<mode>3"
6390   [(set (reg:CCC FLAGS_REG)
6391         (compare:CCC
6392           (plus:SWI48
6393             (match_operand:SWI48 1 "nonimmediate_operand" "%0")
6394             (plus:SWI48
6395               (match_operator 4 "ix86_carry_flag_operator"
6396                [(match_operand 3 "flags_reg_operand") (const_int 0)])
6397               (match_operand:SWI48 2 "nonimmediate_operand" "rm")))
6398           (const_int 0)))
6399    (set (match_operand:SWI48 0 "register_operand" "=r")
6400         (plus:SWI48 (match_dup 1)
6401                     (plus:SWI48 (match_op_dup 4
6402                                  [(match_dup 3) (const_int 0)])
6403                                 (match_dup 2))))]
6404   "TARGET_ADX && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6405   "adcx\t{%2, %0|%0, %2}"
6406   [(set_attr "type" "alu")
6407    (set_attr "use_carry" "1")
6408    (set_attr "mode" "<MODE>")])
6409 \f
6410 ;; Overflow setting add instructions
6411
6412 (define_insn "*add<mode>3_cconly_overflow"
6413   [(set (reg:CCC FLAGS_REG)
6414         (compare:CCC
6415           (plus:SWI
6416             (match_operand:SWI 1 "nonimmediate_operand" "%0")
6417             (match_operand:SWI 2 "<general_operand>" "<g>"))
6418           (match_dup 1)))
6419    (clobber (match_scratch:SWI 0 "=<r>"))]
6420   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6421   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
6422   [(set_attr "type" "alu")
6423    (set_attr "mode" "<MODE>")])
6424
6425 (define_insn "*add<mode>3_cc_overflow"
6426   [(set (reg:CCC FLAGS_REG)
6427         (compare:CCC
6428             (plus:SWI
6429                 (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
6430                 (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
6431             (match_dup 1)))
6432    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6433         (plus:SWI (match_dup 1) (match_dup 2)))]
6434   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6435   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
6436   [(set_attr "type" "alu")
6437    (set_attr "mode" "<MODE>")])
6438
6439 (define_insn "*addsi3_zext_cc_overflow"
6440   [(set (reg:CCC FLAGS_REG)
6441         (compare:CCC
6442           (plus:SI
6443             (match_operand:SI 1 "nonimmediate_operand" "%0")
6444             (match_operand:SI 2 "x86_64_general_operand" "rme"))
6445           (match_dup 1)))
6446    (set (match_operand:DI 0 "register_operand" "=r")
6447         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6448   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
6449   "add{l}\t{%2, %k0|%k0, %2}"
6450   [(set_attr "type" "alu")
6451    (set_attr "mode" "SI")])
6452
6453 ;; The patterns that match these are at the end of this file.
6454
6455 (define_expand "<plusminus_insn>xf3"
6456   [(set (match_operand:XF 0 "register_operand")
6457         (plusminus:XF
6458           (match_operand:XF 1 "register_operand")
6459           (match_operand:XF 2 "register_operand")))]
6460   "TARGET_80387")
6461
6462 (define_expand "<plusminus_insn><mode>3"
6463   [(set (match_operand:MODEF 0 "register_operand")
6464         (plusminus:MODEF
6465           (match_operand:MODEF 1 "register_operand")
6466           (match_operand:MODEF 2 "nonimmediate_operand")))]
6467   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
6468     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
6469 \f
6470 ;; Multiply instructions
6471
6472 (define_expand "mul<mode>3"
6473   [(parallel [(set (match_operand:SWIM248 0 "register_operand")
6474                    (mult:SWIM248
6475                      (match_operand:SWIM248 1 "register_operand")
6476                      (match_operand:SWIM248 2 "<general_operand>")))
6477               (clobber (reg:CC FLAGS_REG))])])
6478
6479 (define_expand "mulqi3"
6480   [(parallel [(set (match_operand:QI 0 "register_operand")
6481                    (mult:QI
6482                      (match_operand:QI 1 "register_operand")
6483                      (match_operand:QI 2 "nonimmediate_operand")))
6484               (clobber (reg:CC FLAGS_REG))])]
6485   "TARGET_QIMODE_MATH")
6486
6487 ;; On AMDFAM10
6488 ;; IMUL reg32/64, reg32/64, imm8        Direct
6489 ;; IMUL reg32/64, mem32/64, imm8        VectorPath
6490 ;; IMUL reg32/64, reg32/64, imm32       Direct
6491 ;; IMUL reg32/64, mem32/64, imm32       VectorPath
6492 ;; IMUL reg32/64, reg32/64              Direct
6493 ;; IMUL reg32/64, mem32/64              Direct
6494 ;;
6495 ;; On BDVER1, all above IMULs use DirectPath
6496
6497 (define_insn "*mul<mode>3_1"
6498   [(set (match_operand:SWI48 0 "register_operand" "=r,r,r")
6499         (mult:SWI48
6500           (match_operand:SWI48 1 "nonimmediate_operand" "%rm,rm,0")
6501           (match_operand:SWI48 2 "<general_operand>" "K,<i>,mr")))
6502    (clobber (reg:CC FLAGS_REG))]
6503   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6504   "@
6505    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6506    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6507    imul{<imodesuffix>}\t{%2, %0|%0, %2}"
6508   [(set_attr "type" "imul")
6509    (set_attr "prefix_0f" "0,0,1")
6510    (set (attr "athlon_decode")
6511         (cond [(eq_attr "cpu" "athlon")
6512                   (const_string "vector")
6513                (eq_attr "alternative" "1")
6514                   (const_string "vector")
6515                (and (eq_attr "alternative" "2")
6516                     (match_operand 1 "memory_operand"))
6517                   (const_string "vector")]
6518               (const_string "direct")))
6519    (set (attr "amdfam10_decode")
6520         (cond [(and (eq_attr "alternative" "0,1")
6521                     (match_operand 1 "memory_operand"))
6522                   (const_string "vector")]
6523               (const_string "direct")))
6524    (set_attr "bdver1_decode" "direct")
6525    (set_attr "mode" "<MODE>")])
6526
6527 (define_insn "*mulsi3_1_zext"
6528   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
6529         (zero_extend:DI
6530           (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,rm,0")
6531                    (match_operand:SI 2 "x86_64_general_operand" "K,e,mr"))))
6532    (clobber (reg:CC FLAGS_REG))]
6533   "TARGET_64BIT
6534    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6535   "@
6536    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
6537    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
6538    imul{l}\t{%2, %k0|%k0, %2}"
6539   [(set_attr "type" "imul")
6540    (set_attr "prefix_0f" "0,0,1")
6541    (set (attr "athlon_decode")
6542         (cond [(eq_attr "cpu" "athlon")
6543                   (const_string "vector")
6544                (eq_attr "alternative" "1")
6545                   (const_string "vector")
6546                (and (eq_attr "alternative" "2")
6547                     (match_operand 1 "memory_operand"))
6548                   (const_string "vector")]
6549               (const_string "direct")))
6550    (set (attr "amdfam10_decode")
6551         (cond [(and (eq_attr "alternative" "0,1")
6552                     (match_operand 1 "memory_operand"))
6553                   (const_string "vector")]
6554               (const_string "direct")))
6555    (set_attr "bdver1_decode" "direct")
6556    (set_attr "mode" "SI")])
6557
6558 ;; On AMDFAM10
6559 ;; IMUL reg16, reg16, imm8      VectorPath
6560 ;; IMUL reg16, mem16, imm8      VectorPath
6561 ;; IMUL reg16, reg16, imm16     VectorPath
6562 ;; IMUL reg16, mem16, imm16     VectorPath
6563 ;; IMUL reg16, reg16            Direct
6564 ;; IMUL reg16, mem16            Direct
6565 ;;
6566 ;; On BDVER1, all HI MULs use DoublePath
6567
6568 (define_insn "*mulhi3_1"
6569   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
6570         (mult:HI (match_operand:HI 1 "nonimmediate_operand" "%rm,rm,0")
6571                  (match_operand:HI 2 "general_operand" "K,n,mr")))
6572    (clobber (reg:CC FLAGS_REG))]
6573   "TARGET_HIMODE_MATH
6574    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6575   "@
6576    imul{w}\t{%2, %1, %0|%0, %1, %2}
6577    imul{w}\t{%2, %1, %0|%0, %1, %2}
6578    imul{w}\t{%2, %0|%0, %2}"
6579   [(set_attr "type" "imul")
6580    (set_attr "prefix_0f" "0,0,1")
6581    (set (attr "athlon_decode")
6582         (cond [(eq_attr "cpu" "athlon")
6583                   (const_string "vector")
6584                (eq_attr "alternative" "1,2")
6585                   (const_string "vector")]
6586               (const_string "direct")))
6587    (set (attr "amdfam10_decode")
6588         (cond [(eq_attr "alternative" "0,1")
6589                   (const_string "vector")]
6590               (const_string "direct")))
6591    (set_attr "bdver1_decode" "double")
6592    (set_attr "mode" "HI")])
6593
6594 ;;On AMDFAM10 and BDVER1
6595 ;; MUL reg8     Direct
6596 ;; MUL mem8     Direct
6597
6598 (define_insn "*mulqi3_1"
6599   [(set (match_operand:QI 0 "register_operand" "=a")
6600         (mult:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
6601                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
6602    (clobber (reg:CC FLAGS_REG))]
6603   "TARGET_QIMODE_MATH
6604    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6605   "mul{b}\t%2"
6606   [(set_attr "type" "imul")
6607    (set_attr "length_immediate" "0")
6608    (set (attr "athlon_decode")
6609      (if_then_else (eq_attr "cpu" "athlon")
6610         (const_string "vector")
6611         (const_string "direct")))
6612    (set_attr "amdfam10_decode" "direct")
6613    (set_attr "bdver1_decode" "direct")
6614    (set_attr "mode" "QI")])
6615
6616 ;; Multiply with jump on overflow.
6617 (define_expand "mulv<mode>4"
6618   [(parallel [(set (reg:CCO FLAGS_REG)
6619                    (eq:CCO (mult:<DWI>
6620                               (sign_extend:<DWI>
6621                                  (match_operand:SWI48 1 "register_operand"))
6622                               (match_dup 4))
6623                            (sign_extend:<DWI>
6624                               (mult:SWI48 (match_dup 1)
6625                                           (match_operand:SWI48 2
6626                                              "<general_operand>")))))
6627               (set (match_operand:SWI48 0 "register_operand")
6628                    (mult:SWI48 (match_dup 1) (match_dup 2)))])
6629    (set (pc) (if_then_else
6630                (eq (reg:CCO FLAGS_REG) (const_int 0))
6631                (label_ref (match_operand 3))
6632                (pc)))]
6633   ""
6634 {
6635   if (CONST_INT_P (operands[2]))
6636     operands[4] = operands[2];
6637   else
6638     operands[4] = gen_rtx_SIGN_EXTEND (<DWI>mode, operands[2]);
6639 })
6640
6641 (define_insn "*mulv<mode>4"
6642   [(set (reg:CCO FLAGS_REG)
6643         (eq:CCO (mult:<DWI>
6644                    (sign_extend:<DWI>
6645                       (match_operand:SWI48 1 "nonimmediate_operand" "%rm,0"))
6646                    (sign_extend:<DWI>
6647                       (match_operand:SWI48 2 "<general_sext_operand>"
6648                                              "We,mr")))
6649                 (sign_extend:<DWI>
6650                    (mult:SWI48 (match_dup 1) (match_dup 2)))))
6651    (set (match_operand:SWI48 0 "register_operand" "=r,r")
6652         (mult:SWI48 (match_dup 1) (match_dup 2)))]
6653   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6654   "@
6655    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6656    imul{<imodesuffix>}\t{%2, %0|%0, %2}"
6657   [(set_attr "type" "imul")
6658    (set_attr "prefix_0f" "0,1")
6659    (set (attr "athlon_decode")
6660         (cond [(eq_attr "cpu" "athlon")
6661                   (const_string "vector")
6662                (eq_attr "alternative" "0")
6663                   (const_string "vector")
6664                (and (eq_attr "alternative" "1")
6665                     (match_operand 1 "memory_operand"))
6666                   (const_string "vector")]
6667               (const_string "direct")))
6668    (set (attr "amdfam10_decode")
6669         (cond [(and (eq_attr "alternative" "1")
6670                     (match_operand 1 "memory_operand"))
6671                   (const_string "vector")]
6672               (const_string "direct")))
6673    (set_attr "bdver1_decode" "direct")
6674    (set_attr "mode" "<MODE>")])
6675
6676 (define_insn "*mulv<mode>4_1"
6677   [(set (reg:CCO FLAGS_REG)
6678         (eq:CCO (mult:<DWI>
6679                    (sign_extend:<DWI>
6680                       (match_operand:SWI48 1 "nonimmediate_operand" "rm,rm"))
6681                    (match_operand:<DWI> 3 "const_int_operand" "K,i"))
6682                 (sign_extend:<DWI>
6683                    (mult:SWI48 (match_dup 1)
6684                                (match_operand:SWI 2 "x86_64_immediate_operand"
6685                                                     "K,<i>")))))
6686    (set (match_operand:SWI48 0 "register_operand" "=r,r")
6687         (mult:SWI48 (match_dup 1) (match_dup 2)))]
6688   "!(MEM_P (operands[1]) && MEM_P (operands[2]))
6689    && CONST_INT_P (operands[2])
6690    && INTVAL (operands[2]) == INTVAL (operands[3])"
6691   "@
6692    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6693    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}"
6694   [(set_attr "type" "imul")
6695    (set (attr "athlon_decode")
6696         (cond [(eq_attr "cpu" "athlon")
6697                   (const_string "vector")
6698                (eq_attr "alternative" "1")
6699                   (const_string "vector")]
6700               (const_string "direct")))
6701    (set (attr "amdfam10_decode")
6702         (cond [(match_operand 1 "memory_operand")
6703                   (const_string "vector")]
6704               (const_string "direct")))
6705    (set_attr "bdver1_decode" "direct")
6706    (set_attr "mode" "<MODE>")
6707    (set (attr "length_immediate")
6708         (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
6709                   (const_string "1")
6710                (match_test "<MODE_SIZE> == 8")
6711                   (const_string "4")]
6712               (const_string "<MODE_SIZE>")))])
6713
6714 (define_expand "umulv<mode>4"
6715   [(parallel [(set (reg:CCO FLAGS_REG)
6716                    (eq:CCO (mult:<DWI>
6717                               (zero_extend:<DWI>
6718                                  (match_operand:SWI48 1
6719                                                       "nonimmediate_operand"))
6720                               (zero_extend:<DWI>
6721                                  (match_operand:SWI48 2
6722                                                       "nonimmediate_operand")))
6723                            (zero_extend:<DWI>
6724                               (mult:SWI48 (match_dup 1) (match_dup 2)))))
6725               (set (match_operand:SWI48 0 "register_operand")
6726                    (mult:SWI48 (match_dup 1) (match_dup 2)))
6727               (clobber (match_scratch:SWI48 4))])
6728    (set (pc) (if_then_else
6729                (eq (reg:CCO FLAGS_REG) (const_int 0))
6730                (label_ref (match_operand 3))
6731                (pc)))]
6732   ""
6733 {
6734   if (MEM_P (operands[1]) && MEM_P (operands[2]))
6735     operands[1] = force_reg (<MODE>mode, operands[1]);
6736 })
6737
6738 (define_insn "*umulv<mode>4"
6739   [(set (reg:CCO FLAGS_REG)
6740         (eq:CCO (mult:<DWI>
6741                    (zero_extend:<DWI>
6742                       (match_operand:SWI48 1 "nonimmediate_operand" "%0"))
6743                    (zero_extend:<DWI>
6744                       (match_operand:SWI48 2 "nonimmediate_operand" "rm")))
6745                 (zero_extend:<DWI>
6746                    (mult:SWI48 (match_dup 1) (match_dup 2)))))
6747    (set (match_operand:SWI48 0 "register_operand" "=a")
6748         (mult:SWI48 (match_dup 1) (match_dup 2)))
6749    (clobber (match_scratch:SWI48 3 "=d"))]
6750   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6751   "mul{<imodesuffix>}\t%2"
6752   [(set_attr "type" "imul")
6753    (set_attr "length_immediate" "0")
6754    (set (attr "athlon_decode")
6755      (if_then_else (eq_attr "cpu" "athlon")
6756        (const_string "vector")
6757        (const_string "double")))
6758    (set_attr "amdfam10_decode" "double")
6759    (set_attr "bdver1_decode" "direct")
6760    (set_attr "mode" "<MODE>")])
6761
6762 (define_expand "<u>mulvqi4"
6763   [(parallel [(set (reg:CCO FLAGS_REG)
6764                    (eq:CCO (mult:HI
6765                               (any_extend:HI
6766                                  (match_operand:QI 1 "nonimmediate_operand"))
6767                               (any_extend:HI
6768                                  (match_operand:QI 2 "nonimmediate_operand")))
6769                            (any_extend:HI
6770                               (mult:QI (match_dup 1) (match_dup 2)))))
6771               (set (match_operand:QI 0 "register_operand")
6772                    (mult:QI (match_dup 1) (match_dup 2)))])
6773    (set (pc) (if_then_else
6774                (eq (reg:CCO FLAGS_REG) (const_int 0))
6775                (label_ref (match_operand 3))
6776                (pc)))]
6777   "TARGET_QIMODE_MATH"
6778 {
6779   if (MEM_P (operands[1]) && MEM_P (operands[2]))
6780     operands[1] = force_reg (QImode, operands[1]);
6781 })
6782
6783 (define_insn "*<u>mulvqi4"
6784   [(set (reg:CCO FLAGS_REG)
6785         (eq:CCO (mult:HI
6786                    (any_extend:HI
6787                       (match_operand:QI 1 "nonimmediate_operand" "%0"))
6788                    (any_extend:HI
6789                       (match_operand:QI 2 "nonimmediate_operand" "qm")))
6790                 (any_extend:HI
6791                    (mult:QI (match_dup 1) (match_dup 2)))))
6792    (set (match_operand:QI 0 "register_operand" "=a")
6793         (mult:QI (match_dup 1) (match_dup 2)))]
6794   "TARGET_QIMODE_MATH
6795    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6796   "<sgnprefix>mul{b}\t%2"
6797   [(set_attr "type" "imul")
6798    (set_attr "length_immediate" "0")
6799    (set (attr "athlon_decode")
6800      (if_then_else (eq_attr "cpu" "athlon")
6801         (const_string "vector")
6802         (const_string "direct")))
6803    (set_attr "amdfam10_decode" "direct")
6804    (set_attr "bdver1_decode" "direct")
6805    (set_attr "mode" "QI")])
6806
6807 (define_expand "<u>mul<mode><dwi>3"
6808   [(parallel [(set (match_operand:<DWI> 0 "register_operand")
6809                    (mult:<DWI>
6810                      (any_extend:<DWI>
6811                        (match_operand:DWIH 1 "nonimmediate_operand"))
6812                      (any_extend:<DWI>
6813                        (match_operand:DWIH 2 "register_operand"))))
6814               (clobber (reg:CC FLAGS_REG))])])
6815
6816 (define_expand "<u>mulqihi3"
6817   [(parallel [(set (match_operand:HI 0 "register_operand")
6818                    (mult:HI
6819                      (any_extend:HI
6820                        (match_operand:QI 1 "nonimmediate_operand"))
6821                      (any_extend:HI
6822                        (match_operand:QI 2 "register_operand"))))
6823               (clobber (reg:CC FLAGS_REG))])]
6824   "TARGET_QIMODE_MATH")
6825
6826 (define_insn "*bmi2_umulditi3_1"
6827   [(set (match_operand:DI 0 "register_operand" "=r")
6828         (mult:DI
6829           (match_operand:DI 2 "nonimmediate_operand" "%d")
6830           (match_operand:DI 3 "nonimmediate_operand" "rm")))
6831    (set (match_operand:DI 1 "register_operand" "=r")
6832         (truncate:DI
6833           (lshiftrt:TI
6834             (mult:TI (zero_extend:TI (match_dup 2))
6835                      (zero_extend:TI (match_dup 3)))
6836             (const_int 64))))]
6837   "TARGET_64BIT && TARGET_BMI2
6838    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6839   "mulx\t{%3, %0, %1|%1, %0, %3}"
6840   [(set_attr "type" "imulx")
6841    (set_attr "prefix" "vex")
6842    (set_attr "mode" "DI")])
6843
6844 (define_insn "*bmi2_umulsidi3_1"
6845   [(set (match_operand:SI 0 "register_operand" "=r")
6846         (mult:SI
6847           (match_operand:SI 2 "nonimmediate_operand" "%d")
6848           (match_operand:SI 3 "nonimmediate_operand" "rm")))
6849    (set (match_operand:SI 1 "register_operand" "=r")
6850         (truncate:SI
6851           (lshiftrt:DI
6852             (mult:DI (zero_extend:DI (match_dup 2))
6853                      (zero_extend:DI (match_dup 3)))
6854             (const_int 32))))]
6855   "!TARGET_64BIT && TARGET_BMI2
6856    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6857   "mulx\t{%3, %0, %1|%1, %0, %3}"
6858   [(set_attr "type" "imulx")
6859    (set_attr "prefix" "vex")
6860    (set_attr "mode" "SI")])
6861
6862 (define_insn "*umul<mode><dwi>3_1"
6863   [(set (match_operand:<DWI> 0 "register_operand" "=r,A")
6864         (mult:<DWI>
6865           (zero_extend:<DWI>
6866             (match_operand:DWIH 1 "nonimmediate_operand" "%d,0"))
6867           (zero_extend:<DWI>
6868             (match_operand:DWIH 2 "nonimmediate_operand" "rm,rm"))))
6869    (clobber (reg:CC FLAGS_REG))]
6870   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6871   "@
6872    #
6873    mul{<imodesuffix>}\t%2"
6874   [(set_attr "isa" "bmi2,*")
6875    (set_attr "type" "imulx,imul")
6876    (set_attr "length_immediate" "*,0")
6877    (set (attr "athlon_decode")
6878         (cond [(eq_attr "alternative" "1")
6879                  (if_then_else (eq_attr "cpu" "athlon")
6880                    (const_string "vector")
6881                    (const_string "double"))]
6882               (const_string "*")))
6883    (set_attr "amdfam10_decode" "*,double")
6884    (set_attr "bdver1_decode" "*,direct")
6885    (set_attr "prefix" "vex,orig")
6886    (set_attr "mode" "<MODE>")])
6887
6888 ;; Convert mul to the mulx pattern to avoid flags dependency.
6889 (define_split
6890  [(set (match_operand:<DWI> 0 "register_operand")
6891        (mult:<DWI>
6892          (zero_extend:<DWI>
6893            (match_operand:DWIH 1 "register_operand"))
6894          (zero_extend:<DWI>
6895            (match_operand:DWIH 2 "nonimmediate_operand"))))
6896   (clobber (reg:CC FLAGS_REG))]
6897  "TARGET_BMI2 && reload_completed
6898   && true_regnum (operands[1]) == DX_REG"
6899   [(parallel [(set (match_dup 3)
6900                    (mult:DWIH (match_dup 1) (match_dup 2)))
6901               (set (match_dup 4)
6902                    (truncate:DWIH
6903                      (lshiftrt:<DWI>
6904                        (mult:<DWI> (zero_extend:<DWI> (match_dup 1))
6905                                    (zero_extend:<DWI> (match_dup 2)))
6906                        (match_dup 5))))])]
6907 {
6908   split_double_mode (<DWI>mode, &operands[0], 1, &operands[3], &operands[4]);
6909
6910   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
6911 })
6912
6913 (define_insn "*mul<mode><dwi>3_1"
6914   [(set (match_operand:<DWI> 0 "register_operand" "=A")
6915         (mult:<DWI>
6916           (sign_extend:<DWI>
6917             (match_operand:DWIH 1 "nonimmediate_operand" "%0"))
6918           (sign_extend:<DWI>
6919             (match_operand:DWIH 2 "nonimmediate_operand" "rm"))))
6920    (clobber (reg:CC FLAGS_REG))]
6921   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6922   "imul{<imodesuffix>}\t%2"
6923   [(set_attr "type" "imul")
6924    (set_attr "length_immediate" "0")
6925    (set (attr "athlon_decode")
6926      (if_then_else (eq_attr "cpu" "athlon")
6927         (const_string "vector")
6928         (const_string "double")))
6929    (set_attr "amdfam10_decode" "double")
6930    (set_attr "bdver1_decode" "direct")
6931    (set_attr "mode" "<MODE>")])
6932
6933 (define_insn "*<u>mulqihi3_1"
6934   [(set (match_operand:HI 0 "register_operand" "=a")
6935         (mult:HI
6936           (any_extend:HI
6937             (match_operand:QI 1 "nonimmediate_operand" "%0"))
6938           (any_extend:HI
6939             (match_operand:QI 2 "nonimmediate_operand" "qm"))))
6940    (clobber (reg:CC FLAGS_REG))]
6941   "TARGET_QIMODE_MATH
6942    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6943   "<sgnprefix>mul{b}\t%2"
6944   [(set_attr "type" "imul")
6945    (set_attr "length_immediate" "0")
6946    (set (attr "athlon_decode")
6947      (if_then_else (eq_attr "cpu" "athlon")
6948         (const_string "vector")
6949         (const_string "direct")))
6950    (set_attr "amdfam10_decode" "direct")
6951    (set_attr "bdver1_decode" "direct")
6952    (set_attr "mode" "QI")])
6953
6954 (define_expand "<s>mul<mode>3_highpart"
6955   [(parallel [(set (match_operand:SWI48 0 "register_operand")
6956                    (truncate:SWI48
6957                      (lshiftrt:<DWI>
6958                        (mult:<DWI>
6959                          (any_extend:<DWI>
6960                            (match_operand:SWI48 1 "nonimmediate_operand"))
6961                          (any_extend:<DWI>
6962                            (match_operand:SWI48 2 "register_operand")))
6963                        (match_dup 4))))
6964               (clobber (match_scratch:SWI48 3))
6965               (clobber (reg:CC FLAGS_REG))])]
6966   ""
6967   "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
6968
6969 (define_insn "*<s>muldi3_highpart_1"
6970   [(set (match_operand:DI 0 "register_operand" "=d")
6971         (truncate:DI
6972           (lshiftrt:TI
6973             (mult:TI
6974               (any_extend:TI
6975                 (match_operand:DI 1 "nonimmediate_operand" "%a"))
6976               (any_extend:TI
6977                 (match_operand:DI 2 "nonimmediate_operand" "rm")))
6978             (const_int 64))))
6979    (clobber (match_scratch:DI 3 "=1"))
6980    (clobber (reg:CC FLAGS_REG))]
6981   "TARGET_64BIT
6982    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6983   "<sgnprefix>mul{q}\t%2"
6984   [(set_attr "type" "imul")
6985    (set_attr "length_immediate" "0")
6986    (set (attr "athlon_decode")
6987      (if_then_else (eq_attr "cpu" "athlon")
6988         (const_string "vector")
6989         (const_string "double")))
6990    (set_attr "amdfam10_decode" "double")
6991    (set_attr "bdver1_decode" "direct")
6992    (set_attr "mode" "DI")])
6993
6994 (define_insn "*<s>mulsi3_highpart_1"
6995   [(set (match_operand:SI 0 "register_operand" "=d")
6996         (truncate:SI
6997           (lshiftrt:DI
6998             (mult:DI
6999               (any_extend:DI
7000                 (match_operand:SI 1 "nonimmediate_operand" "%a"))
7001               (any_extend:DI
7002                 (match_operand:SI 2 "nonimmediate_operand" "rm")))
7003             (const_int 32))))
7004    (clobber (match_scratch:SI 3 "=1"))
7005    (clobber (reg:CC FLAGS_REG))]
7006   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
7007   "<sgnprefix>mul{l}\t%2"
7008   [(set_attr "type" "imul")
7009    (set_attr "length_immediate" "0")
7010    (set (attr "athlon_decode")
7011      (if_then_else (eq_attr "cpu" "athlon")
7012         (const_string "vector")
7013         (const_string "double")))
7014    (set_attr "amdfam10_decode" "double")
7015    (set_attr "bdver1_decode" "direct")
7016    (set_attr "mode" "SI")])
7017
7018 (define_insn "*<s>mulsi3_highpart_zext"
7019   [(set (match_operand:DI 0 "register_operand" "=d")
7020         (zero_extend:DI (truncate:SI
7021           (lshiftrt:DI
7022             (mult:DI (any_extend:DI
7023                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
7024                      (any_extend:DI
7025                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7026             (const_int 32)))))
7027    (clobber (match_scratch:SI 3 "=1"))
7028    (clobber (reg:CC FLAGS_REG))]
7029   "TARGET_64BIT
7030    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7031   "<sgnprefix>mul{l}\t%2"
7032   [(set_attr "type" "imul")
7033    (set_attr "length_immediate" "0")
7034    (set (attr "athlon_decode")
7035      (if_then_else (eq_attr "cpu" "athlon")
7036         (const_string "vector")
7037         (const_string "double")))
7038    (set_attr "amdfam10_decode" "double")
7039    (set_attr "bdver1_decode" "direct")
7040    (set_attr "mode" "SI")])
7041
7042 ;; The patterns that match these are at the end of this file.
7043
7044 (define_expand "mulxf3"
7045   [(set (match_operand:XF 0 "register_operand")
7046         (mult:XF (match_operand:XF 1 "register_operand")
7047                  (match_operand:XF 2 "register_operand")))]
7048   "TARGET_80387")
7049
7050 (define_expand "mul<mode>3"
7051   [(set (match_operand:MODEF 0 "register_operand")
7052         (mult:MODEF (match_operand:MODEF 1 "register_operand")
7053                     (match_operand:MODEF 2 "nonimmediate_operand")))]
7054   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
7055     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
7056 \f
7057 ;; Divide instructions
7058
7059 ;; The patterns that match these are at the end of this file.
7060
7061 (define_expand "divxf3"
7062   [(set (match_operand:XF 0 "register_operand")
7063         (div:XF (match_operand:XF 1 "register_operand")
7064                 (match_operand:XF 2 "register_operand")))]
7065   "TARGET_80387")
7066
7067 (define_expand "divdf3"
7068   [(set (match_operand:DF 0 "register_operand")
7069         (div:DF (match_operand:DF 1 "register_operand")
7070                 (match_operand:DF 2 "nonimmediate_operand")))]
7071    "(TARGET_80387 && X87_ENABLE_ARITH (DFmode))
7072     || (TARGET_SSE2 && TARGET_SSE_MATH)")
7073
7074 (define_expand "divsf3"
7075   [(set (match_operand:SF 0 "register_operand")
7076         (div:SF (match_operand:SF 1 "register_operand")
7077                 (match_operand:SF 2 "nonimmediate_operand")))]
7078   "(TARGET_80387 && X87_ENABLE_ARITH (SFmode))
7079     || TARGET_SSE_MATH"
7080 {
7081   if (TARGET_SSE_MATH
7082       && TARGET_RECIP_DIV
7083       && optimize_insn_for_speed_p ()
7084       && flag_finite_math_only && !flag_trapping_math
7085       && flag_unsafe_math_optimizations)
7086     {
7087       ix86_emit_swdivsf (operands[0], operands[1],
7088                          operands[2], SFmode);
7089       DONE;
7090     }
7091 })
7092 \f
7093 ;; Divmod instructions.
7094
7095 (define_expand "divmod<mode>4"
7096   [(parallel [(set (match_operand:SWIM248 0 "register_operand")
7097                    (div:SWIM248
7098                      (match_operand:SWIM248 1 "register_operand")
7099                      (match_operand:SWIM248 2 "nonimmediate_operand")))
7100               (set (match_operand:SWIM248 3 "register_operand")
7101                    (mod:SWIM248 (match_dup 1) (match_dup 2)))
7102               (clobber (reg:CC FLAGS_REG))])])
7103
7104 ;; Split with 8bit unsigned divide:
7105 ;;      if (dividend an divisor are in [0-255])
7106 ;;         use 8bit unsigned integer divide
7107 ;;       else
7108 ;;         use original integer divide
7109 (define_split
7110   [(set (match_operand:SWI48 0 "register_operand")
7111         (div:SWI48 (match_operand:SWI48 2 "register_operand")
7112                     (match_operand:SWI48 3 "nonimmediate_operand")))
7113    (set (match_operand:SWI48 1 "register_operand")
7114         (mod:SWI48 (match_dup 2) (match_dup 3)))
7115    (clobber (reg:CC FLAGS_REG))]
7116   "TARGET_USE_8BIT_IDIV
7117    && TARGET_QIMODE_MATH
7118    && can_create_pseudo_p ()
7119    && !optimize_insn_for_size_p ()"
7120   [(const_int 0)]
7121   "ix86_split_idivmod (<MODE>mode, operands, true); DONE;")
7122
7123 (define_insn_and_split "divmod<mode>4_1"
7124   [(set (match_operand:SWI48 0 "register_operand" "=a")
7125         (div:SWI48 (match_operand:SWI48 2 "register_operand" "0")
7126                    (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
7127    (set (match_operand:SWI48 1 "register_operand" "=&d")
7128         (mod:SWI48 (match_dup 2) (match_dup 3)))
7129    (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
7130    (clobber (reg:CC FLAGS_REG))]
7131   ""
7132   "#"
7133   "reload_completed"
7134   [(parallel [(set (match_dup 1)
7135                    (ashiftrt:SWI48 (match_dup 4) (match_dup 5)))
7136               (clobber (reg:CC FLAGS_REG))])
7137    (parallel [(set (match_dup 0)
7138                    (div:SWI48 (match_dup 2) (match_dup 3)))
7139               (set (match_dup 1)
7140                    (mod:SWI48 (match_dup 2) (match_dup 3)))
7141               (use (match_dup 1))
7142               (clobber (reg:CC FLAGS_REG))])]
7143 {
7144   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
7145
7146   if (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
7147     operands[4] = operands[2];
7148   else
7149     {
7150       /* Avoid use of cltd in favor of a mov+shift.  */
7151       emit_move_insn (operands[1], operands[2]);
7152       operands[4] = operands[1];
7153     }
7154 }
7155   [(set_attr "type" "multi")
7156    (set_attr "mode" "<MODE>")])
7157
7158 (define_insn_and_split "*divmod<mode>4"
7159   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7160         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7161                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7162    (set (match_operand:SWIM248 1 "register_operand" "=&d")
7163         (mod:SWIM248 (match_dup 2) (match_dup 3)))
7164    (clobber (reg:CC FLAGS_REG))]
7165   ""
7166   "#"
7167   "reload_completed"
7168   [(parallel [(set (match_dup 1)
7169                    (ashiftrt:SWIM248 (match_dup 4) (match_dup 5)))
7170               (clobber (reg:CC FLAGS_REG))])
7171    (parallel [(set (match_dup 0)
7172                    (div:SWIM248 (match_dup 2) (match_dup 3)))
7173               (set (match_dup 1)
7174                    (mod:SWIM248 (match_dup 2) (match_dup 3)))
7175               (use (match_dup 1))
7176               (clobber (reg:CC FLAGS_REG))])]
7177 {
7178   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
7179
7180   if (<MODE>mode != HImode
7181       && (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD))
7182     operands[4] = operands[2];
7183   else
7184     {
7185       /* Avoid use of cltd in favor of a mov+shift.  */
7186       emit_move_insn (operands[1], operands[2]);
7187       operands[4] = operands[1];
7188     }
7189 }
7190   [(set_attr "type" "multi")
7191    (set_attr "mode" "<MODE>")])
7192
7193 (define_insn "*divmod<mode>4_noext"
7194   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7195         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7196                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7197    (set (match_operand:SWIM248 1 "register_operand" "=d")
7198         (mod:SWIM248 (match_dup 2) (match_dup 3)))
7199    (use (match_operand:SWIM248 4 "register_operand" "1"))
7200    (clobber (reg:CC FLAGS_REG))]
7201   ""
7202   "idiv{<imodesuffix>}\t%3"
7203   [(set_attr "type" "idiv")
7204    (set_attr "mode" "<MODE>")])
7205
7206 (define_expand "divmodqi4"
7207   [(parallel [(set (match_operand:QI 0 "register_operand")
7208                    (div:QI
7209                      (match_operand:QI 1 "register_operand")
7210                      (match_operand:QI 2 "nonimmediate_operand")))
7211               (set (match_operand:QI 3 "register_operand")
7212                    (mod:QI (match_dup 1) (match_dup 2)))
7213               (clobber (reg:CC FLAGS_REG))])]
7214   "TARGET_QIMODE_MATH"
7215 {
7216   rtx div, mod, insn;
7217   rtx tmp0, tmp1;
7218   
7219   tmp0 = gen_reg_rtx (HImode);
7220   tmp1 = gen_reg_rtx (HImode);
7221
7222   /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
7223      in AX.  */
7224   emit_insn (gen_extendqihi2 (tmp1, operands[1]));
7225   emit_insn (gen_divmodhiqi3 (tmp0, tmp1, operands[2]));
7226
7227   /* Extract remainder from AH.  */
7228   tmp1 = gen_rtx_SIGN_EXTRACT (QImode, tmp0, GEN_INT (8), GEN_INT (8));
7229   insn = emit_move_insn (operands[3], tmp1);
7230
7231   mod = gen_rtx_MOD (QImode, operands[1], operands[2]);
7232   set_unique_reg_note (insn, REG_EQUAL, mod);
7233
7234   /* Extract quotient from AL.  */
7235   insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
7236
7237   div = gen_rtx_DIV (QImode, operands[1], operands[2]);
7238   set_unique_reg_note (insn, REG_EQUAL, div);
7239
7240   DONE;
7241 })
7242
7243 ;; Divide AX by r/m8, with result stored in
7244 ;; AL <- Quotient
7245 ;; AH <- Remainder
7246 ;; Change div/mod to HImode and extend the second argument to HImode
7247 ;; so that mode of div/mod matches with mode of arguments.  Otherwise
7248 ;; combine may fail.
7249 (define_insn "divmodhiqi3"
7250   [(set (match_operand:HI 0 "register_operand" "=a")
7251         (ior:HI
7252           (ashift:HI
7253             (zero_extend:HI
7254               (truncate:QI
7255                 (mod:HI (match_operand:HI 1 "register_operand" "0")
7256                         (sign_extend:HI
7257                           (match_operand:QI 2 "nonimmediate_operand" "qm")))))
7258             (const_int 8))
7259           (zero_extend:HI
7260             (truncate:QI
7261               (div:HI (match_dup 1) (sign_extend:HI (match_dup 2)))))))
7262    (clobber (reg:CC FLAGS_REG))]
7263   "TARGET_QIMODE_MATH"
7264   "idiv{b}\t%2"
7265   [(set_attr "type" "idiv")
7266    (set_attr "mode" "QI")])
7267
7268 (define_expand "udivmod<mode>4"
7269   [(parallel [(set (match_operand:SWIM248 0 "register_operand")
7270                    (udiv:SWIM248
7271                      (match_operand:SWIM248 1 "register_operand")
7272                      (match_operand:SWIM248 2 "nonimmediate_operand")))
7273               (set (match_operand:SWIM248 3 "register_operand")
7274                    (umod:SWIM248 (match_dup 1) (match_dup 2)))
7275               (clobber (reg:CC FLAGS_REG))])])
7276
7277 ;; Split with 8bit unsigned divide:
7278 ;;      if (dividend an divisor are in [0-255])
7279 ;;         use 8bit unsigned integer divide
7280 ;;       else
7281 ;;         use original integer divide
7282 (define_split
7283   [(set (match_operand:SWI48 0 "register_operand")
7284         (udiv:SWI48 (match_operand:SWI48 2 "register_operand")
7285                     (match_operand:SWI48 3 "nonimmediate_operand")))
7286    (set (match_operand:SWI48 1 "register_operand")
7287         (umod:SWI48 (match_dup 2) (match_dup 3)))
7288    (clobber (reg:CC FLAGS_REG))]
7289   "TARGET_USE_8BIT_IDIV
7290    && TARGET_QIMODE_MATH
7291    && can_create_pseudo_p ()
7292    && !optimize_insn_for_size_p ()"
7293   [(const_int 0)]
7294   "ix86_split_idivmod (<MODE>mode, operands, false); DONE;")
7295
7296 (define_insn_and_split "udivmod<mode>4_1"
7297   [(set (match_operand:SWI48 0 "register_operand" "=a")
7298         (udiv:SWI48 (match_operand:SWI48 2 "register_operand" "0")
7299                     (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
7300    (set (match_operand:SWI48 1 "register_operand" "=&d")
7301         (umod:SWI48 (match_dup 2) (match_dup 3)))
7302    (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
7303    (clobber (reg:CC FLAGS_REG))]
7304   ""
7305   "#"
7306   "reload_completed"
7307   [(set (match_dup 1) (const_int 0))
7308    (parallel [(set (match_dup 0)
7309                    (udiv:SWI48 (match_dup 2) (match_dup 3)))
7310               (set (match_dup 1)
7311                    (umod:SWI48 (match_dup 2) (match_dup 3)))
7312               (use (match_dup 1))
7313               (clobber (reg:CC FLAGS_REG))])]
7314   ""
7315   [(set_attr "type" "multi")
7316    (set_attr "mode" "<MODE>")])
7317
7318 (define_insn_and_split "*udivmod<mode>4"
7319   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7320         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7321                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7322    (set (match_operand:SWIM248 1 "register_operand" "=&d")
7323         (umod:SWIM248 (match_dup 2) (match_dup 3)))
7324    (clobber (reg:CC FLAGS_REG))]
7325   ""
7326   "#"
7327   "reload_completed"
7328   [(set (match_dup 1) (const_int 0))
7329    (parallel [(set (match_dup 0)
7330                    (udiv:SWIM248 (match_dup 2) (match_dup 3)))
7331               (set (match_dup 1)
7332                    (umod:SWIM248 (match_dup 2) (match_dup 3)))
7333               (use (match_dup 1))
7334               (clobber (reg:CC FLAGS_REG))])]
7335   ""
7336   [(set_attr "type" "multi")
7337    (set_attr "mode" "<MODE>")])
7338
7339 ;; Optimize division or modulo by constant power of 2, if the constant
7340 ;; materializes only after expansion.
7341 (define_insn_and_split "*udivmod<mode>4_pow2"
7342   [(set (match_operand:SWI48 0 "register_operand" "=r")
7343         (udiv:SWI48 (match_operand:SWI48 2 "register_operand" "0")
7344                     (match_operand:SWI48 3 "const_int_operand" "n")))
7345    (set (match_operand:SWI48 1 "register_operand" "=r")
7346         (umod:SWI48 (match_dup 2) (match_dup 3)))
7347    (clobber (reg:CC FLAGS_REG))]
7348   "IN_RANGE (INTVAL (operands[3]), 2, HOST_WIDE_INT_UC (0x80000000))
7349    && (UINTVAL (operands[3]) & (UINTVAL (operands[3]) - 1)) == 0"
7350   "#"
7351   "&& 1"
7352   [(set (match_dup 1) (match_dup 2))
7353    (parallel [(set (match_dup 0) (lshiftrt:<MODE> (match_dup 2) (match_dup 4)))
7354               (clobber (reg:CC FLAGS_REG))])
7355    (parallel [(set (match_dup 1) (and:<MODE> (match_dup 1) (match_dup 5)))
7356               (clobber (reg:CC FLAGS_REG))])]
7357 {
7358   int v = exact_log2 (UINTVAL (operands[3]));
7359   operands[4] = GEN_INT (v);
7360   operands[5] = GEN_INT ((HOST_WIDE_INT_1U << v) - 1);
7361 }
7362   [(set_attr "type" "multi")
7363    (set_attr "mode" "<MODE>")])
7364
7365 (define_insn "*udivmod<mode>4_noext"
7366   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7367         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7368                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7369    (set (match_operand:SWIM248 1 "register_operand" "=d")
7370         (umod:SWIM248 (match_dup 2) (match_dup 3)))
7371    (use (match_operand:SWIM248 4 "register_operand" "1"))
7372    (clobber (reg:CC FLAGS_REG))]
7373   ""
7374   "div{<imodesuffix>}\t%3"
7375   [(set_attr "type" "idiv")
7376    (set_attr "mode" "<MODE>")])
7377
7378 (define_expand "udivmodqi4"
7379   [(parallel [(set (match_operand:QI 0 "register_operand")
7380                    (udiv:QI
7381                      (match_operand:QI 1 "register_operand")
7382                      (match_operand:QI 2 "nonimmediate_operand")))
7383               (set (match_operand:QI 3 "register_operand")
7384                    (umod:QI (match_dup 1) (match_dup 2)))
7385               (clobber (reg:CC FLAGS_REG))])]
7386   "TARGET_QIMODE_MATH"
7387 {
7388   rtx div, mod, insn;
7389   rtx tmp0, tmp1;
7390   
7391   tmp0 = gen_reg_rtx (HImode);
7392   tmp1 = gen_reg_rtx (HImode);
7393
7394   /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
7395      in AX.  */
7396   emit_insn (gen_zero_extendqihi2 (tmp1, operands[1]));
7397   emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, operands[2]));
7398
7399   /* Extract remainder from AH.  */
7400   tmp1 = gen_rtx_ZERO_EXTRACT (SImode, tmp0, GEN_INT (8), GEN_INT (8));
7401   tmp1 = simplify_gen_subreg (QImode, tmp1, SImode, 0);
7402   insn = emit_move_insn (operands[3], tmp1);
7403
7404   mod = gen_rtx_UMOD (QImode, operands[1], operands[2]);
7405   set_unique_reg_note (insn, REG_EQUAL, mod);
7406
7407   /* Extract quotient from AL.  */
7408   insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
7409
7410   div = gen_rtx_UDIV (QImode, operands[1], operands[2]);
7411   set_unique_reg_note (insn, REG_EQUAL, div);
7412
7413   DONE;
7414 })
7415
7416 (define_insn "udivmodhiqi3"
7417   [(set (match_operand:HI 0 "register_operand" "=a")
7418         (ior:HI
7419           (ashift:HI
7420             (zero_extend:HI
7421               (truncate:QI
7422                 (mod:HI (match_operand:HI 1 "register_operand" "0")
7423                         (zero_extend:HI
7424                           (match_operand:QI 2 "nonimmediate_operand" "qm")))))
7425             (const_int 8))
7426           (zero_extend:HI
7427             (truncate:QI
7428               (div:HI (match_dup 1) (zero_extend:HI (match_dup 2)))))))
7429    (clobber (reg:CC FLAGS_REG))]
7430   "TARGET_QIMODE_MATH"
7431   "div{b}\t%2"
7432   [(set_attr "type" "idiv")
7433    (set_attr "mode" "QI")])
7434
7435 ;; We cannot use div/idiv for double division, because it causes
7436 ;; "division by zero" on the overflow and that's not what we expect
7437 ;; from truncate.  Because true (non truncating) double division is
7438 ;; never generated, we can't create this insn anyway.
7439 ;
7440 ;(define_insn ""
7441 ;  [(set (match_operand:SI 0 "register_operand" "=a")
7442 ;       (truncate:SI
7443 ;         (udiv:DI (match_operand:DI 1 "register_operand" "A")
7444 ;                  (zero_extend:DI
7445 ;                    (match_operand:SI 2 "nonimmediate_operand" "rm")))))
7446 ;   (set (match_operand:SI 3 "register_operand" "=d")
7447 ;       (truncate:SI
7448 ;         (umod:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))
7449 ;   (clobber (reg:CC FLAGS_REG))]
7450 ;  ""
7451 ;  "div{l}\t{%2, %0|%0, %2}"
7452 ;  [(set_attr "type" "idiv")])
7453 \f
7454 ;;- Logical AND instructions
7455
7456 ;; On Pentium, "test imm, reg" is pairable only with eax, ax, and al.
7457 ;; Note that this excludes ah.
7458
7459 (define_expand "testsi_ccno_1"
7460   [(set (reg:CCNO FLAGS_REG)
7461         (compare:CCNO
7462           (and:SI (match_operand:SI 0 "nonimmediate_operand")
7463                   (match_operand:SI 1 "x86_64_nonmemory_operand"))
7464           (const_int 0)))])
7465
7466 (define_expand "testqi_ccz_1"
7467   [(set (reg:CCZ FLAGS_REG)
7468         (compare:CCZ (and:QI (match_operand:QI 0 "nonimmediate_operand")
7469                              (match_operand:QI 1 "nonmemory_operand"))
7470                  (const_int 0)))])
7471
7472 (define_expand "testdi_ccno_1"
7473   [(set (reg:CCNO FLAGS_REG)
7474         (compare:CCNO
7475           (and:DI (match_operand:DI 0 "nonimmediate_operand")
7476                   (match_operand:DI 1 "x86_64_szext_general_operand"))
7477           (const_int 0)))]
7478   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))")
7479
7480 (define_insn "*testdi_1"
7481   [(set (reg FLAGS_REG)
7482         (compare
7483          (and:DI
7484           (match_operand:DI 0 "nonimmediate_operand" "%!*a,r,!*a,r,rm")
7485           (match_operand:DI 1 "x86_64_szext_general_operand" "Z,Z,e,e,re"))
7486          (const_int 0)))]
7487   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
7488    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7489   "@
7490    test{l}\t{%k1, %k0|%k0, %k1}
7491    test{l}\t{%k1, %k0|%k0, %k1}
7492    test{q}\t{%1, %0|%0, %1}
7493    test{q}\t{%1, %0|%0, %1}
7494    test{q}\t{%1, %0|%0, %1}"
7495   [(set_attr "type" "test")
7496    (set_attr "modrm" "0,1,0,1,1")
7497    (set_attr "mode" "SI,SI,DI,DI,DI")])
7498
7499 (define_insn "*testqi_1_maybe_si"
7500   [(set (reg FLAGS_REG)
7501         (compare
7502           (and:QI
7503             (match_operand:QI 0 "nonimmediate_operand" "%!*a,q,qm,r")
7504             (match_operand:QI 1 "general_operand" "n,n,qn,n"))
7505           (const_int 0)))]
7506    "!(MEM_P (operands[0]) && MEM_P (operands[1]))
7507     && ix86_match_ccmode (insn,
7508                          CONST_INT_P (operands[1])
7509                          && INTVAL (operands[1]) >= 0 ? CCNOmode : CCZmode)"
7510 {
7511   if (which_alternative == 3)
7512     {
7513       if (CONST_INT_P (operands[1]) && INTVAL (operands[1]) < 0)
7514         operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff);
7515       return "test{l}\t{%1, %k0|%k0, %1}";
7516     }
7517   return "test{b}\t{%1, %0|%0, %1}";
7518 }
7519   [(set_attr "type" "test")
7520    (set_attr "modrm" "0,1,1,1")
7521    (set_attr "mode" "QI,QI,QI,SI")
7522    (set_attr "pent_pair" "uv,np,uv,np")])
7523
7524 (define_insn "*test<mode>_1"
7525   [(set (reg FLAGS_REG)
7526         (compare
7527          (and:SWI124
7528           (match_operand:SWI124 0 "nonimmediate_operand" "%!*a,<r>,<r>m")
7529           (match_operand:SWI124 1 "<general_operand>" "<i>,<i>,<r><i>"))
7530          (const_int 0)))]
7531   "ix86_match_ccmode (insn, CCNOmode)
7532    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7533   "test{<imodesuffix>}\t{%1, %0|%0, %1}"
7534   [(set_attr "type" "test")
7535    (set_attr "modrm" "0,1,1")
7536    (set_attr "mode" "<MODE>")
7537    (set_attr "pent_pair" "uv,np,uv")])
7538
7539 (define_expand "testqi_ext_ccno_0"
7540   [(set (reg:CCNO FLAGS_REG)
7541         (compare:CCNO
7542           (and:SI
7543             (zero_extract:SI
7544               (match_operand 0 "ext_register_operand")
7545               (const_int 8)
7546               (const_int 8))
7547             (match_operand 1 "const_int_operand"))
7548           (const_int 0)))])
7549
7550 (define_insn "*testqi_ext_0"
7551   [(set (reg FLAGS_REG)
7552         (compare
7553           (and:SI
7554             (zero_extract:SI
7555               (match_operand 0 "ext_register_operand" "Q")
7556               (const_int 8)
7557               (const_int 8))
7558             (match_operand 1 "const_int_operand" "n"))
7559           (const_int 0)))]
7560   "ix86_match_ccmode (insn, CCNOmode)"
7561   "test{b}\t{%1, %h0|%h0, %1}"
7562   [(set_attr "type" "test")
7563    (set_attr "mode" "QI")
7564    (set_attr "length_immediate" "1")
7565    (set_attr "modrm" "1")
7566    (set_attr "pent_pair" "np")])
7567
7568 (define_insn "*testqi_ext_1"
7569   [(set (reg FLAGS_REG)
7570         (compare
7571           (and:SI
7572             (zero_extract:SI
7573               (match_operand 0 "ext_register_operand" "Q,Q")
7574               (const_int 8)
7575               (const_int 8))
7576             (zero_extend:SI
7577               (match_operand:QI 1 "nonimmediate_x64nomem_operand" "Q,m")))
7578           (const_int 0)))]
7579   "ix86_match_ccmode (insn, CCNOmode)"
7580   "test{b}\t{%1, %h0|%h0, %1}"
7581   [(set_attr "isa" "*,nox64")
7582    (set_attr "type" "test")
7583    (set_attr "mode" "QI")])
7584
7585 (define_insn "*testqi_ext_2"
7586   [(set (reg FLAGS_REG)
7587         (compare
7588           (and:SI
7589             (zero_extract:SI
7590               (match_operand 0 "ext_register_operand" "Q")
7591               (const_int 8)
7592               (const_int 8))
7593             (zero_extract:SI
7594               (match_operand 1 "ext_register_operand" "Q")
7595               (const_int 8)
7596               (const_int 8)))
7597           (const_int 0)))]
7598   "ix86_match_ccmode (insn, CCNOmode)"
7599   "test{b}\t{%h1, %h0|%h0, %h1}"
7600   [(set_attr "type" "test")
7601    (set_attr "mode" "QI")])
7602
7603 ;; Combine likes to form bit extractions for some tests.  Humor it.
7604 (define_insn "*testqi_ext_3"
7605   [(set (reg FLAGS_REG)
7606         (compare (zero_extract:SWI48
7607                    (match_operand 0 "nonimmediate_operand" "rm")
7608                    (match_operand:SWI48 1 "const_int_operand")
7609                    (match_operand:SWI48 2 "const_int_operand"))
7610                  (const_int 0)))]
7611   "ix86_match_ccmode (insn, CCNOmode)
7612    && ((TARGET_64BIT && GET_MODE (operands[0]) == DImode)
7613        || GET_MODE (operands[0]) == SImode
7614        || GET_MODE (operands[0]) == HImode
7615        || GET_MODE (operands[0]) == QImode)
7616    /* Ensure that resulting mask is zero or sign extended operand.  */
7617    && INTVAL (operands[2]) >= 0
7618    && ((INTVAL (operands[1]) > 0
7619         && INTVAL (operands[1]) + INTVAL (operands[2]) <= 32)
7620        || (<MODE>mode == DImode
7621            && INTVAL (operands[1]) > 32
7622            && INTVAL (operands[1]) + INTVAL (operands[2]) == 64))"
7623   "#")
7624
7625 (define_split
7626   [(set (match_operand 0 "flags_reg_operand")
7627         (match_operator 1 "compare_operator"
7628           [(zero_extract
7629              (match_operand 2 "nonimmediate_operand")
7630              (match_operand 3 "const_int_operand")
7631              (match_operand 4 "const_int_operand"))
7632            (const_int 0)]))]
7633   "ix86_match_ccmode (insn, CCNOmode)"
7634   [(set (match_dup 0) (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
7635 {
7636   rtx val = operands[2];
7637   HOST_WIDE_INT len = INTVAL (operands[3]);
7638   HOST_WIDE_INT pos = INTVAL (operands[4]);
7639   HOST_WIDE_INT mask;
7640   machine_mode mode, submode;
7641
7642   mode = GET_MODE (val);
7643   if (MEM_P (val))
7644     {
7645       /* ??? Combine likes to put non-volatile mem extractions in QImode
7646          no matter the size of the test.  So find a mode that works.  */
7647       if (! MEM_VOLATILE_P (val))
7648         {
7649           mode = smallest_mode_for_size (pos + len, MODE_INT);
7650           val = adjust_address (val, mode, 0);
7651         }
7652     }
7653   else if (GET_CODE (val) == SUBREG
7654            && (submode = GET_MODE (SUBREG_REG (val)),
7655                GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (submode))
7656            && pos + len <= GET_MODE_BITSIZE (submode)
7657            && GET_MODE_CLASS (submode) == MODE_INT)
7658     {
7659       /* Narrow a paradoxical subreg to prevent partial register stalls.  */
7660       mode = submode;
7661       val = SUBREG_REG (val);
7662     }
7663   else if (mode == HImode && pos + len <= 8)
7664     {
7665       /* Small HImode tests can be converted to QImode.  */
7666       mode = QImode;
7667       val = gen_lowpart (QImode, val);
7668     }
7669
7670   if (len == HOST_BITS_PER_WIDE_INT)
7671     mask = -1;
7672   else
7673     mask = ((HOST_WIDE_INT)1 << len) - 1;
7674   mask <<= pos;
7675
7676   operands[2] = gen_rtx_AND (mode, val, gen_int_mode (mask, mode));
7677 })
7678
7679 ;; Convert HImode/SImode test instructions with immediate to QImode ones.
7680 ;; i386 does not allow to encode test with 8bit sign extended immediate, so
7681 ;; this is relatively important trick.
7682 ;; Do the conversion only post-reload to avoid limiting of the register class
7683 ;; to QI regs.
7684 (define_split
7685   [(set (match_operand 0 "flags_reg_operand")
7686         (match_operator 1 "compare_operator"
7687           [(and (match_operand 2 "register_operand")
7688                 (match_operand 3 "const_int_operand"))
7689            (const_int 0)]))]
7690    "reload_completed
7691     && QI_REG_P (operands[2])
7692     && GET_MODE (operands[2]) != QImode
7693     && ((ix86_match_ccmode (insn, CCZmode)
7694          && !(INTVAL (operands[3]) & ~(255 << 8)))
7695         || (ix86_match_ccmode (insn, CCNOmode)
7696             && !(INTVAL (operands[3]) & ~(127 << 8))))"
7697   [(set (match_dup 0)
7698         (match_op_dup 1
7699           [(and:SI (zero_extract:SI (match_dup 2) (const_int 8) (const_int 8))
7700                    (match_dup 3))
7701            (const_int 0)]))]
7702 {
7703   operands[2] = gen_lowpart (SImode, operands[2]);
7704   operands[3] = gen_int_mode (INTVAL (operands[3]) >> 8, SImode);
7705 })
7706
7707 (define_split
7708   [(set (match_operand 0 "flags_reg_operand")
7709         (match_operator 1 "compare_operator"
7710           [(and (match_operand 2 "nonimmediate_operand")
7711                 (match_operand 3 "const_int_operand"))
7712            (const_int 0)]))]
7713    "reload_completed
7714     && GET_MODE (operands[2]) != QImode
7715     && (!REG_P (operands[2]) || ANY_QI_REG_P (operands[2]))
7716     && ((ix86_match_ccmode (insn, CCZmode)
7717          && !(INTVAL (operands[3]) & ~255))
7718         || (ix86_match_ccmode (insn, CCNOmode)
7719             && !(INTVAL (operands[3]) & ~127)))"
7720   [(set (match_dup 0)
7721         (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
7722                          (const_int 0)]))]
7723 {
7724   operands[2] = gen_lowpart (QImode, operands[2]);
7725   operands[3] = gen_lowpart (QImode, operands[3]);
7726 })
7727
7728 (define_split
7729   [(set (match_operand:SWI1248x 0 "mask_reg_operand")
7730         (any_logic:SWI1248x (match_operand:SWI1248x 1 "mask_reg_operand")
7731                             (match_operand:SWI1248x 2 "mask_reg_operand")))
7732    (clobber (reg:CC FLAGS_REG))]
7733   "TARGET_AVX512F && reload_completed"
7734   [(set (match_dup 0)
7735         (any_logic:SWI1248x (match_dup 1)
7736                             (match_dup 2)))])
7737
7738 (define_insn "*k<logic><mode>"
7739   [(set (match_operand:SWI1248_AVX512BW 0 "mask_reg_operand" "=k")
7740         (any_logic:SWI1248_AVX512BW (match_operand:SWI1248_AVX512BW 1 "mask_reg_operand" "k")
7741                           (match_operand:SWI1248_AVX512BW 2 "mask_reg_operand" "k")))]
7742   "TARGET_AVX512F"
7743   {
7744     if (!TARGET_AVX512DQ && <MODE>mode == QImode)
7745       return "k<logic>w\t{%2, %1, %0|%0, %1, %2}";
7746     else
7747       return "k<logic><mskmodesuffix>\t{%2, %1, %0|%0, %1, %2}";
7748   }
7749   [(set_attr "mode" "<MODE>")
7750    (set_attr "type" "msklog")
7751    (set_attr "prefix" "vex")])
7752
7753 ;; %%% This used to optimize known byte-wide and operations to memory,
7754 ;; and sometimes to QImode registers.  If this is considered useful,
7755 ;; it should be done with splitters.
7756
7757 (define_expand "and<mode>3"
7758   [(set (match_operand:SWIM 0 "nonimmediate_operand")
7759         (and:SWIM (match_operand:SWIM 1 "nonimmediate_operand")
7760                   (match_operand:SWIM 2 "<general_szext_operand>")))]
7761   ""
7762 {
7763   machine_mode mode = <MODE>mode;
7764   rtx (*insn) (rtx, rtx);
7765
7766   if (CONST_INT_P (operands[2]) && REG_P (operands[0]))
7767     {
7768       HOST_WIDE_INT ival = INTVAL (operands[2]);
7769
7770       if (ival == (HOST_WIDE_INT) 0xffffffff)
7771         mode = SImode;
7772       else if (ival == 0xffff)
7773         mode = HImode;
7774       else if (ival == 0xff)
7775         mode = QImode;
7776       }
7777
7778   if (mode == <MODE>mode)
7779     {
7780       ix86_expand_binary_operator (AND, <MODE>mode, operands);
7781       DONE;
7782     }
7783
7784   if (<MODE>mode == DImode)
7785     insn = (mode == SImode)
7786            ? gen_zero_extendsidi2
7787            : (mode == HImode)
7788            ? gen_zero_extendhidi2
7789            : gen_zero_extendqidi2;
7790   else if (<MODE>mode == SImode)
7791     insn = (mode == HImode)
7792            ? gen_zero_extendhisi2
7793            : gen_zero_extendqisi2;
7794   else if (<MODE>mode == HImode)
7795     insn = gen_zero_extendqihi2;
7796   else
7797     gcc_unreachable ();
7798
7799   emit_insn (insn (operands[0], gen_lowpart (mode, operands[1])));
7800   DONE;
7801 })
7802
7803 (define_insn "*anddi_1"
7804   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r,r,!k")
7805         (and:DI
7806          (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,qm,k")
7807          (match_operand:DI 2 "x86_64_szext_general_operand" "Z,re,rm,L,k")))
7808    (clobber (reg:CC FLAGS_REG))]
7809   "TARGET_64BIT && ix86_binary_operator_ok (AND, DImode, operands)"
7810 {
7811   switch (get_attr_type (insn))
7812     {
7813     case TYPE_IMOVX:
7814       return "#";
7815
7816     case TYPE_MSKLOG:
7817       return "kandq\t{%2, %1, %0|%0, %1, %2}";
7818
7819     default:
7820       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7821       if (get_attr_mode (insn) == MODE_SI)
7822         return "and{l}\t{%k2, %k0|%k0, %k2}";
7823       else
7824         return "and{q}\t{%2, %0|%0, %2}";
7825     }
7826 }
7827   [(set_attr "type" "alu,alu,alu,imovx,msklog")
7828    (set_attr "length_immediate" "*,*,*,0,0")
7829    (set (attr "prefix_rex")
7830      (if_then_else
7831        (and (eq_attr "type" "imovx")
7832             (and (match_test "INTVAL (operands[2]) == 0xff")
7833                  (match_operand 1 "ext_QIreg_operand")))
7834        (const_string "1")
7835        (const_string "*")))
7836    (set_attr "mode" "SI,DI,DI,SI,DI")])
7837
7838 (define_insn "*andsi_1"
7839   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r,Ya,!k")
7840         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,qm,k")
7841                 (match_operand:SI 2 "x86_64_general_operand" "re,rm,L,k")))
7842    (clobber (reg:CC FLAGS_REG))]
7843   "ix86_binary_operator_ok (AND, SImode, operands)"
7844 {
7845   switch (get_attr_type (insn))
7846     {
7847     case TYPE_IMOVX:
7848       return "#";
7849
7850     case TYPE_MSKLOG:
7851       return "kandd\t{%2, %1, %0|%0, %1, %2}";
7852
7853     default:
7854       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7855       return "and{l}\t{%2, %0|%0, %2}";
7856     }
7857 }
7858   [(set_attr "type" "alu,alu,imovx,msklog")
7859    (set (attr "prefix_rex")
7860      (if_then_else
7861        (and (eq_attr "type" "imovx")
7862             (and (match_test "INTVAL (operands[2]) == 0xff")
7863                  (match_operand 1 "ext_QIreg_operand")))
7864        (const_string "1")
7865        (const_string "*")))
7866    (set_attr "length_immediate" "*,*,0,0")
7867    (set_attr "mode" "SI")])
7868
7869 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
7870 (define_insn "*andsi_1_zext"
7871   [(set (match_operand:DI 0 "register_operand" "=r")
7872         (zero_extend:DI
7873           (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
7874                   (match_operand:SI 2 "x86_64_general_operand" "rme"))))
7875    (clobber (reg:CC FLAGS_REG))]
7876   "TARGET_64BIT && ix86_binary_operator_ok (AND, SImode, operands)"
7877   "and{l}\t{%2, %k0|%k0, %2}"
7878   [(set_attr "type" "alu")
7879    (set_attr "mode" "SI")])
7880
7881 (define_insn "*andhi_1"
7882   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,Ya,!k")
7883         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,qm,k")
7884                 (match_operand:HI 2 "general_operand" "rn,rm,L,k")))
7885    (clobber (reg:CC FLAGS_REG))]
7886   "ix86_binary_operator_ok (AND, HImode, operands)"
7887 {
7888   switch (get_attr_type (insn))
7889     {
7890     case TYPE_IMOVX:
7891       return "#";
7892
7893     case TYPE_MSKLOG:
7894       return "kandw\t{%2, %1, %0|%0, %1, %2}";
7895
7896     default:
7897       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7898       return "and{w}\t{%2, %0|%0, %2}";
7899     }
7900 }
7901   [(set_attr "type" "alu,alu,imovx,msklog")
7902    (set_attr "length_immediate" "*,*,0,*")
7903    (set (attr "prefix_rex")
7904      (if_then_else
7905        (and (eq_attr "type" "imovx")
7906             (match_operand 1 "ext_QIreg_operand"))
7907        (const_string "1")
7908        (const_string "*")))
7909    (set_attr "mode" "HI,HI,SI,HI")])
7910
7911 ;; %%% Potential partial reg stall on alternative 2.  What to do?
7912 (define_insn "*andqi_1"
7913   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r,!k")
7914         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,k")
7915                 (match_operand:QI 2 "general_operand" "qn,qmn,rn,k")))
7916    (clobber (reg:CC FLAGS_REG))]
7917   "ix86_binary_operator_ok (AND, QImode, operands)"
7918 {
7919   switch (which_alternative)
7920     {
7921     case 0:
7922     case 1:
7923       return "and{b}\t{%2, %0|%0, %2}";
7924     case 2:
7925       return "and{l}\t{%k2, %k0|%k0, %k2}";
7926     case 3:
7927       return TARGET_AVX512DQ ? "kandb\t{%2, %1, %0|%0, %1, %2}"
7928                              : "kandw\t{%2, %1, %0|%0, %1, %2}";
7929     default:
7930       gcc_unreachable ();
7931     }
7932 }
7933   [(set_attr "type" "alu,alu,alu,msklog")
7934    (set_attr "mode" "QI,QI,SI,HI")])
7935
7936 (define_insn "*andqi_1_slp"
7937   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
7938         (and:QI (match_dup 0)
7939                 (match_operand:QI 1 "general_operand" "qn,qmn")))
7940    (clobber (reg:CC FLAGS_REG))]
7941   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
7942    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7943   "and{b}\t{%1, %0|%0, %1}"
7944   [(set_attr "type" "alu1")
7945    (set_attr "mode" "QI")])
7946
7947 (define_insn "kandn<mode>"
7948   [(set (match_operand:SWI12 0 "register_operand" "=r,&r,!k")
7949         (and:SWI12
7950           (not:SWI12
7951             (match_operand:SWI12 1 "register_operand" "r,0,k"))
7952           (match_operand:SWI12 2 "register_operand" "r,r,k")))
7953    (clobber (reg:CC FLAGS_REG))]
7954   "TARGET_AVX512F"
7955 {
7956   switch (which_alternative)
7957     {
7958     case 0:
7959       return "andn\t{%k2, %k1, %k0|%k0, %k1, %k2}";
7960     case 1:
7961       return "#";
7962     case 2:
7963       if (TARGET_AVX512DQ && <MODE>mode == QImode)
7964         return "kandnb\t{%2, %1, %0|%0, %1, %2}";
7965       else
7966         return "kandnw\t{%2, %1, %0|%0, %1, %2}";
7967     default:
7968       gcc_unreachable ();
7969     }
7970 }
7971   [(set_attr "isa" "bmi,*,avx512f")
7972    (set_attr "type" "bitmanip,*,msklog")
7973    (set_attr "prefix" "*,*,vex")
7974    (set_attr "btver2_decode" "direct,*,*")
7975    (set_attr "mode" "<MODE>")])
7976
7977 (define_split
7978   [(set (match_operand:SWI12 0 "general_reg_operand")
7979         (and:SWI12
7980           (not:SWI12
7981             (match_dup 0))
7982           (match_operand:SWI12 1 "general_reg_operand")))
7983    (clobber (reg:CC FLAGS_REG))]
7984   "TARGET_AVX512F && !TARGET_BMI && reload_completed"
7985   [(set (match_dup 0)
7986         (not:HI (match_dup 0)))
7987    (parallel [(set (match_dup 0)
7988                    (and:HI (match_dup 0)
7989                            (match_dup 1)))
7990               (clobber (reg:CC FLAGS_REG))])])
7991
7992 ;; Turn *anddi_1 into *andsi_1_zext if possible.
7993 (define_split
7994   [(set (match_operand:DI 0 "register_operand")
7995         (and:DI (subreg:DI (match_operand:SI 1 "register_operand") 0)
7996                 (match_operand:DI 2 "x86_64_zext_immediate_operand")))
7997    (clobber (reg:CC FLAGS_REG))]
7998   "TARGET_64BIT"
7999   [(parallel [(set (match_dup 0)
8000                    (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))
8001               (clobber (reg:CC FLAGS_REG))])]
8002   "operands[2] = gen_lowpart (SImode, operands[2]);")
8003
8004 (define_split
8005   [(set (match_operand:SWI248 0 "register_operand")
8006         (and:SWI248 (match_operand:SWI248 1 "nonimmediate_operand")
8007                     (match_operand:SWI248 2 "const_int_operand")))
8008    (clobber (reg:CC FLAGS_REG))]
8009   "reload_completed
8010    && true_regnum (operands[0]) != true_regnum (operands[1])"
8011   [(const_int 0)]
8012 {
8013   HOST_WIDE_INT ival = INTVAL (operands[2]);
8014   machine_mode mode;
8015   rtx (*insn) (rtx, rtx);
8016
8017   if (ival == (HOST_WIDE_INT) 0xffffffff)
8018     mode = SImode;
8019   else if (ival == 0xffff)
8020     mode = HImode;
8021   else
8022     {
8023       gcc_assert (ival == 0xff);
8024       mode = QImode;
8025     }
8026
8027   if (<MODE>mode == DImode)
8028     insn = (mode == SImode)
8029            ? gen_zero_extendsidi2
8030            : (mode == HImode)
8031            ? gen_zero_extendhidi2
8032            : gen_zero_extendqidi2;
8033   else
8034     {
8035       if (<MODE>mode != SImode)
8036         /* Zero extend to SImode to avoid partial register stalls.  */
8037         operands[0] = gen_lowpart (SImode, operands[0]);
8038
8039       insn = (mode == HImode)
8040              ? gen_zero_extendhisi2
8041              : gen_zero_extendqisi2;
8042     }
8043   emit_insn (insn (operands[0], gen_lowpart (mode, operands[1])));
8044   DONE;
8045 })
8046
8047 (define_split
8048   [(set (match_operand 0 "register_operand")
8049         (and (match_dup 0)
8050              (const_int -65536)))
8051    (clobber (reg:CC FLAGS_REG))]
8052   "(TARGET_FAST_PREFIX && !TARGET_PARTIAL_REG_STALL)
8053     || optimize_function_for_size_p (cfun)"
8054   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8055   "operands[1] = gen_lowpart (HImode, operands[0]);")
8056
8057 (define_split
8058   [(set (match_operand 0 "ext_register_operand")
8059         (and (match_dup 0)
8060              (const_int -256)))
8061    (clobber (reg:CC FLAGS_REG))]
8062   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8063    && reload_completed"
8064   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8065   "operands[1] = gen_lowpart (QImode, operands[0]);")
8066
8067 (define_split
8068   [(set (match_operand 0 "ext_register_operand")
8069         (and (match_dup 0)
8070              (const_int -65281)))
8071    (clobber (reg:CC FLAGS_REG))]
8072   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8073    && reload_completed"
8074   [(parallel [(set (zero_extract:SI (match_dup 0)
8075                                     (const_int 8)
8076                                     (const_int 8))
8077                    (xor:SI
8078                      (zero_extract:SI (match_dup 0)
8079                                       (const_int 8)
8080                                       (const_int 8))
8081                      (zero_extract:SI (match_dup 0)
8082                                       (const_int 8)
8083                                       (const_int 8))))
8084               (clobber (reg:CC FLAGS_REG))])]
8085   "operands[0] = gen_lowpart (SImode, operands[0]);")
8086
8087 (define_insn "*anddi_2"
8088   [(set (reg FLAGS_REG)
8089         (compare
8090          (and:DI
8091           (match_operand:DI 1 "nonimmediate_operand" "%0,0,0")
8092           (match_operand:DI 2 "x86_64_szext_general_operand" "Z,rem,re"))
8093          (const_int 0)))
8094    (set (match_operand:DI 0 "nonimmediate_operand" "=r,r,rm")
8095         (and:DI (match_dup 1) (match_dup 2)))]
8096   "TARGET_64BIT
8097    && ix86_match_ccmode
8098         (insn,
8099          /* If we are going to emit andl instead of andq, and the operands[2]
8100             constant might have the SImode sign bit set, make sure the sign
8101             flag isn't tested, because the instruction will set the sign flag
8102             based on bit 31 rather than bit 63.  If it isn't CONST_INT,
8103             conservatively assume it might have bit 31 set.  */
8104          (satisfies_constraint_Z (operands[2])
8105           && (!CONST_INT_P (operands[2])
8106               || val_signbit_known_set_p (SImode, INTVAL (operands[2]))))
8107          ? CCZmode : CCNOmode)
8108    && ix86_binary_operator_ok (AND, DImode, operands)"
8109   "@
8110    and{l}\t{%k2, %k0|%k0, %k2}
8111    and{q}\t{%2, %0|%0, %2}
8112    and{q}\t{%2, %0|%0, %2}"
8113   [(set_attr "type" "alu")
8114    (set_attr "mode" "SI,DI,DI")])
8115
8116 (define_insn "*andqi_2_maybe_si"
8117   [(set (reg FLAGS_REG)
8118         (compare (and:QI
8119                   (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8120                   (match_operand:QI 2 "general_operand" "qmn,qn,n"))
8121                  (const_int 0)))
8122    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm,*r")
8123         (and:QI (match_dup 1) (match_dup 2)))]
8124   "ix86_binary_operator_ok (AND, QImode, operands)
8125    && ix86_match_ccmode (insn,
8126                          CONST_INT_P (operands[2])
8127                          && INTVAL (operands[2]) >= 0 ? CCNOmode : CCZmode)"
8128 {
8129   if (which_alternative == 2)
8130     {
8131       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
8132         operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff);
8133       return "and{l}\t{%2, %k0|%k0, %2}";
8134     }
8135   return "and{b}\t{%2, %0|%0, %2}";
8136 }
8137   [(set_attr "type" "alu")
8138    (set_attr "mode" "QI,QI,SI")])
8139
8140 (define_insn "*and<mode>_2"
8141   [(set (reg FLAGS_REG)
8142         (compare (and:SWI124
8143                   (match_operand:SWI124 1 "nonimmediate_operand" "%0,0")
8144                   (match_operand:SWI124 2 "<general_operand>" "<g>,<r><i>"))
8145                  (const_int 0)))
8146    (set (match_operand:SWI124 0 "nonimmediate_operand" "=<r>,<r>m")
8147         (and:SWI124 (match_dup 1) (match_dup 2)))]
8148   "ix86_match_ccmode (insn, CCNOmode)
8149    && ix86_binary_operator_ok (AND, <MODE>mode, operands)"
8150   "and{<imodesuffix>}\t{%2, %0|%0, %2}"
8151   [(set_attr "type" "alu")
8152    (set_attr "mode" "<MODE>")])
8153
8154 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8155 (define_insn "*andsi_2_zext"
8156   [(set (reg FLAGS_REG)
8157         (compare (and:SI
8158                   (match_operand:SI 1 "nonimmediate_operand" "%0")
8159                   (match_operand:SI 2 "x86_64_general_operand" "rme"))
8160                  (const_int 0)))
8161    (set (match_operand:DI 0 "register_operand" "=r")
8162         (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))]
8163   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8164    && ix86_binary_operator_ok (AND, SImode, operands)"
8165   "and{l}\t{%2, %k0|%k0, %2}"
8166   [(set_attr "type" "alu")
8167    (set_attr "mode" "SI")])
8168
8169 (define_insn "*andqi_2_slp"
8170   [(set (reg FLAGS_REG)
8171         (compare (and:QI
8172                    (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8173                    (match_operand:QI 1 "nonimmediate_operand" "qmn,qn"))
8174                  (const_int 0)))
8175    (set (strict_low_part (match_dup 0))
8176         (and:QI (match_dup 0) (match_dup 1)))]
8177   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8178    && ix86_match_ccmode (insn, CCNOmode)
8179    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8180   "and{b}\t{%1, %0|%0, %1}"
8181   [(set_attr "type" "alu1")
8182    (set_attr "mode" "QI")])
8183
8184 ;; ??? A bug in recog prevents it from recognizing a const_int as an
8185 ;; operand to zero_extend in andqi_ext_1.  It was checking explicitly
8186 ;; for a QImode operand, which of course failed.
8187 (define_insn "andqi_ext_0"
8188   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8189                          (const_int 8)
8190                          (const_int 8))
8191         (and:SI
8192           (zero_extract:SI
8193             (match_operand 1 "ext_register_operand" "0")
8194             (const_int 8)
8195             (const_int 8))
8196           (match_operand 2 "const_int_operand" "n")))
8197    (clobber (reg:CC FLAGS_REG))]
8198   ""
8199   "and{b}\t{%2, %h0|%h0, %2}"
8200   [(set_attr "type" "alu")
8201    (set_attr "length_immediate" "1")
8202    (set_attr "modrm" "1")
8203    (set_attr "mode" "QI")])
8204
8205 ;; Generated by peephole translating test to and.  This shows up
8206 ;; often in fp comparisons.
8207 (define_insn "*andqi_ext_0_cc"
8208   [(set (reg FLAGS_REG)
8209         (compare
8210           (and:SI
8211             (zero_extract:SI
8212               (match_operand 1 "ext_register_operand" "0")
8213               (const_int 8)
8214               (const_int 8))
8215             (match_operand 2 "const_int_operand" "n"))
8216           (const_int 0)))
8217    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8218                          (const_int 8)
8219                          (const_int 8))
8220         (and:SI
8221           (zero_extract:SI
8222             (match_dup 1)
8223             (const_int 8)
8224             (const_int 8))
8225           (match_dup 2)))]
8226   "ix86_match_ccmode (insn, CCNOmode)"
8227   "and{b}\t{%2, %h0|%h0, %2}"
8228   [(set_attr "type" "alu")
8229    (set_attr "length_immediate" "1")
8230    (set_attr "modrm" "1")
8231    (set_attr "mode" "QI")])
8232
8233 (define_insn "*andqi_ext_1"
8234   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
8235                          (const_int 8)
8236                          (const_int 8))
8237         (and:SI
8238           (zero_extract:SI
8239             (match_operand 1 "ext_register_operand" "0,0")
8240             (const_int 8)
8241             (const_int 8))
8242           (zero_extend:SI
8243             (match_operand:QI 2 "nonimmediate_x64nomem_operand" "Q,m"))))
8244    (clobber (reg:CC FLAGS_REG))]
8245   ""
8246   "and{b}\t{%2, %h0|%h0, %2}"
8247   [(set_attr "isa" "*,nox64")
8248    (set_attr "type" "alu")
8249    (set_attr "length_immediate" "0")
8250    (set_attr "mode" "QI")])
8251
8252 (define_insn "*andqi_ext_2"
8253   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8254                          (const_int 8)
8255                          (const_int 8))
8256         (and:SI
8257           (zero_extract:SI
8258             (match_operand 1 "ext_register_operand" "%0")
8259             (const_int 8)
8260             (const_int 8))
8261           (zero_extract:SI
8262             (match_operand 2 "ext_register_operand" "Q")
8263             (const_int 8)
8264             (const_int 8))))
8265    (clobber (reg:CC FLAGS_REG))]
8266   ""
8267   "and{b}\t{%h2, %h0|%h0, %h2}"
8268   [(set_attr "type" "alu")
8269    (set_attr "length_immediate" "0")
8270    (set_attr "mode" "QI")])
8271
8272 ;; Convert wide AND instructions with immediate operand to shorter QImode
8273 ;; equivalents when possible.
8274 ;; Don't do the splitting with memory operands, since it introduces risk
8275 ;; of memory mismatch stalls.  We may want to do the splitting for optimizing
8276 ;; for size, but that can (should?) be handled by generic code instead.
8277 (define_split
8278   [(set (match_operand 0 "register_operand")
8279         (and (match_operand 1 "register_operand")
8280              (match_operand 2 "const_int_operand")))
8281    (clobber (reg:CC FLAGS_REG))]
8282    "reload_completed
8283     && QI_REG_P (operands[0])
8284     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8285     && !(~INTVAL (operands[2]) & ~(255 << 8))
8286     && GET_MODE (operands[0]) != QImode"
8287   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8288                    (and:SI (zero_extract:SI (match_dup 1)
8289                                             (const_int 8) (const_int 8))
8290                            (match_dup 2)))
8291               (clobber (reg:CC FLAGS_REG))])]
8292 {
8293   operands[0] = gen_lowpart (SImode, operands[0]);
8294   operands[1] = gen_lowpart (SImode, operands[1]);
8295   operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);
8296 })
8297
8298 ;; Since AND can be encoded with sign extended immediate, this is only
8299 ;; profitable when 7th bit is not set.
8300 (define_split
8301   [(set (match_operand 0 "register_operand")
8302         (and (match_operand 1 "general_operand")
8303              (match_operand 2 "const_int_operand")))
8304    (clobber (reg:CC FLAGS_REG))]
8305    "reload_completed
8306     && ANY_QI_REG_P (operands[0])
8307     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8308     && !(~INTVAL (operands[2]) & ~255)
8309     && !(INTVAL (operands[2]) & 128)
8310     && GET_MODE (operands[0]) != QImode"
8311   [(parallel [(set (strict_low_part (match_dup 0))
8312                    (and:QI (match_dup 1)
8313                            (match_dup 2)))
8314               (clobber (reg:CC FLAGS_REG))])]
8315 {
8316   operands[0] = gen_lowpart (QImode, operands[0]);
8317   operands[1] = gen_lowpart (QImode, operands[1]);
8318   operands[2] = gen_lowpart (QImode, operands[2]);
8319 })
8320 \f
8321 ;; Logical inclusive and exclusive OR instructions
8322
8323 ;; %%% This used to optimize known byte-wide and operations to memory.
8324 ;; If this is considered useful, it should be done with splitters.
8325
8326 (define_expand "<code><mode>3"
8327   [(set (match_operand:SWIM 0 "nonimmediate_operand")
8328         (any_or:SWIM (match_operand:SWIM 1 "nonimmediate_operand")
8329                      (match_operand:SWIM 2 "<general_operand>")))]
8330   ""
8331   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
8332
8333 (define_insn "*<code><mode>_1"
8334   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm,k")
8335         (any_or:SWI48
8336          (match_operand:SWI48 1 "nonimmediate_operand" "%0,0,k")
8337          (match_operand:SWI48 2 "<general_operand>" "<g>,r<i>,k")))
8338    (clobber (reg:CC FLAGS_REG))]
8339   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
8340   "@
8341    <logic>{<imodesuffix>}\t{%2, %0|%0, %2}
8342    <logic>{<imodesuffix>}\t{%2, %0|%0, %2}
8343    k<logic><mskmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
8344   [(set_attr "type" "alu,alu,msklog")
8345    (set_attr "mode" "<MODE>")])
8346
8347 (define_insn "*<code>hi_1"
8348   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,rm,!k")
8349         (any_or:HI
8350          (match_operand:HI 1 "nonimmediate_operand" "%0,0,k")
8351          (match_operand:HI 2 "general_operand" "<g>,r<i>,k")))
8352    (clobber (reg:CC FLAGS_REG))]
8353   "ix86_binary_operator_ok (<CODE>, HImode, operands)"
8354   "@
8355   <logic>{w}\t{%2, %0|%0, %2}
8356   <logic>{w}\t{%2, %0|%0, %2}
8357   k<logic>w\t{%2, %1, %0|%0, %1, %2}"
8358   [(set_attr "type" "alu,alu,msklog")
8359    (set_attr "mode" "HI")])
8360
8361 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8362 (define_insn "*<code>qi_1"
8363   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r,!k")
8364         (any_or:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,k")
8365                    (match_operand:QI 2 "general_operand" "qmn,qn,rn,k")))
8366    (clobber (reg:CC FLAGS_REG))]
8367   "ix86_binary_operator_ok (<CODE>, QImode, operands)"
8368   "@
8369    <logic>{b}\t{%2, %0|%0, %2}
8370    <logic>{b}\t{%2, %0|%0, %2}
8371    <logic>{l}\t{%k2, %k0|%k0, %k2}
8372    k<logic>w\t{%2, %1, %0|%0, %1, %2}"
8373   [(set_attr "type" "alu,alu,alu,msklog")
8374    (set_attr "mode" "QI,QI,SI,HI")])
8375
8376 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8377 (define_insn "*<code>si_1_zext"
8378   [(set (match_operand:DI 0 "register_operand" "=r")
8379         (zero_extend:DI
8380          (any_or:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8381                     (match_operand:SI 2 "x86_64_general_operand" "rme"))))
8382    (clobber (reg:CC FLAGS_REG))]
8383   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8384   "<logic>{l}\t{%2, %k0|%k0, %2}"
8385   [(set_attr "type" "alu")
8386    (set_attr "mode" "SI")])
8387
8388 (define_insn "*<code>si_1_zext_imm"
8389   [(set (match_operand:DI 0 "register_operand" "=r")
8390         (any_or:DI
8391          (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
8392          (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
8393    (clobber (reg:CC FLAGS_REG))]
8394   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8395   "<logic>{l}\t{%2, %k0|%k0, %2}"
8396   [(set_attr "type" "alu")
8397    (set_attr "mode" "SI")])
8398
8399 (define_insn "*<code>qi_1_slp"
8400   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+q,m"))
8401         (any_or:QI (match_dup 0)
8402                    (match_operand:QI 1 "general_operand" "qmn,qn")))
8403    (clobber (reg:CC FLAGS_REG))]
8404   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8405    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8406   "<logic>{b}\t{%1, %0|%0, %1}"
8407   [(set_attr "type" "alu1")
8408    (set_attr "mode" "QI")])
8409
8410 (define_insn "*<code><mode>_2"
8411   [(set (reg FLAGS_REG)
8412         (compare (any_or:SWI
8413                   (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
8414                   (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>"))
8415                  (const_int 0)))
8416    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
8417         (any_or:SWI (match_dup 1) (match_dup 2)))]
8418   "ix86_match_ccmode (insn, CCNOmode)
8419    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
8420   "<logic>{<imodesuffix>}\t{%2, %0|%0, %2}"
8421   [(set_attr "type" "alu")
8422    (set_attr "mode" "<MODE>")])
8423
8424 (define_insn "kxnor<mode>"
8425   [(set (match_operand:SWI12 0 "register_operand" "=r,!k")
8426         (not:SWI12
8427           (xor:SWI12
8428             (match_operand:SWI12 1 "register_operand" "0,k")
8429             (match_operand:SWI12 2 "register_operand" "r,k"))))
8430    (clobber (reg:CC FLAGS_REG))]
8431   "TARGET_AVX512F"
8432 {
8433   if (which_alternative == 1 && <MODE>mode == QImode && TARGET_AVX512DQ)
8434     return "kxnorb\t{%2, %1, %0|%0, %1, %2}";
8435   return "kxnorw\t{%2, %1, %0|%0, %1, %2}";
8436 }
8437   [(set_attr "type" "*,msklog")
8438    (set_attr "prefix" "*,vex")
8439    (set_attr "mode" "<MODE>")])
8440
8441 (define_insn "kxnor<mode>"
8442   [(set (match_operand:SWI48x 0 "register_operand" "=r,!k")
8443         (not:SWI48x
8444           (xor:SWI48x
8445             (match_operand:SWI48x 1 "register_operand" "0,k")
8446             (match_operand:SWI48x 2 "register_operand" "r,k"))))
8447    (clobber (reg:CC FLAGS_REG))]
8448   "TARGET_AVX512BW"
8449   "@
8450    #
8451    kxnor<mskmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
8452   [(set_attr "type" "*,msklog")
8453    (set_attr "prefix" "*,vex")
8454    (set_attr "mode" "<MODE>")])
8455
8456 (define_split
8457   [(set (match_operand:SWI1248x 0 "general_reg_operand")
8458         (not:SWI1248x
8459           (xor:SWI1248x
8460             (match_dup 0)
8461             (match_operand:SWI1248x 1 "general_reg_operand"))))
8462    (clobber (reg:CC FLAGS_REG))]
8463   "TARGET_AVX512F && reload_completed"
8464    [(parallel [(set (match_dup 0)
8465                     (xor:HI (match_dup 0)
8466                             (match_dup 1)))
8467                (clobber (reg:CC FLAGS_REG))])
8468     (set (match_dup 0)
8469          (not:HI (match_dup 0)))])
8470
8471 ;;There are kortrest[bdq] but no intrinsics for them.
8472 ;;We probably don't need to implement them.
8473 (define_insn "kortestzhi"
8474   [(set (reg:CCZ FLAGS_REG)
8475         (compare:CCZ
8476           (ior:HI
8477             (match_operand:HI 0 "register_operand" "k")
8478             (match_operand:HI 1 "register_operand" "k"))
8479           (const_int 0)))]
8480   "TARGET_AVX512F && ix86_match_ccmode (insn, CCZmode)"
8481   "kortestw\t{%1, %0|%0, %1}"
8482   [(set_attr "mode" "HI")
8483    (set_attr "type" "msklog")
8484    (set_attr "prefix" "vex")])
8485
8486 (define_insn "kortestchi"
8487   [(set (reg:CCC FLAGS_REG)
8488         (compare:CCC
8489           (ior:HI
8490             (match_operand:HI 0 "register_operand" "k")
8491             (match_operand:HI 1 "register_operand" "k"))
8492           (const_int -1)))]
8493   "TARGET_AVX512F && ix86_match_ccmode (insn, CCCmode)"
8494   "kortestw\t{%1, %0|%0, %1}"
8495   [(set_attr "mode" "HI")
8496    (set_attr "type" "msklog")
8497    (set_attr "prefix" "vex")])
8498
8499 (define_insn "kunpckhi"
8500   [(set (match_operand:HI 0 "register_operand" "=k")
8501         (ior:HI
8502           (ashift:HI
8503             (match_operand:HI 1 "register_operand" "k")
8504             (const_int 8))
8505           (zero_extend:HI (match_operand:QI 2 "register_operand" "k"))))]
8506   "TARGET_AVX512F"
8507   "kunpckbw\t{%2, %1, %0|%0, %1, %2}"
8508   [(set_attr "mode" "HI")
8509    (set_attr "type" "msklog")
8510    (set_attr "prefix" "vex")])
8511
8512 (define_insn "kunpcksi"
8513   [(set (match_operand:SI 0 "register_operand" "=k")
8514         (ior:SI
8515           (ashift:SI
8516             (match_operand:SI 1 "register_operand" "k")
8517             (const_int 16))
8518           (zero_extend:SI (subreg:HI (match_operand:SI 2 "register_operand" "k") 0))))]
8519   "TARGET_AVX512BW"
8520   "kunpckwd\t{%2, %1, %0|%0, %1, %2}"
8521   [(set_attr "mode" "SI")])
8522
8523 (define_insn "kunpckdi"
8524   [(set (match_operand:DI 0 "register_operand" "=k")
8525         (ior:DI
8526           (ashift:DI
8527             (match_operand:DI 1 "register_operand" "k")
8528             (const_int 32))
8529           (zero_extend:DI (subreg:SI (match_operand:DI 2 "register_operand" "k") 0))))]
8530   "TARGET_AVX512BW"
8531   "kunpckdq\t{%2, %1, %0|%0, %1, %2}"
8532   [(set_attr "mode" "DI")])
8533
8534 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8535 ;; ??? Special case for immediate operand is missing - it is tricky.
8536 (define_insn "*<code>si_2_zext"
8537   [(set (reg FLAGS_REG)
8538         (compare (any_or:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8539                             (match_operand:SI 2 "x86_64_general_operand" "rme"))
8540                  (const_int 0)))
8541    (set (match_operand:DI 0 "register_operand" "=r")
8542         (zero_extend:DI (any_or:SI (match_dup 1) (match_dup 2))))]
8543   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8544    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8545   "<logic>{l}\t{%2, %k0|%k0, %2}"
8546   [(set_attr "type" "alu")
8547    (set_attr "mode" "SI")])
8548
8549 (define_insn "*<code>si_2_zext_imm"
8550   [(set (reg FLAGS_REG)
8551         (compare (any_or:SI
8552                   (match_operand:SI 1 "nonimmediate_operand" "%0")
8553                   (match_operand:SI 2 "x86_64_zext_immediate_operand" "Z"))
8554                  (const_int 0)))
8555    (set (match_operand:DI 0 "register_operand" "=r")
8556         (any_or:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
8557   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8558    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8559   "<logic>{l}\t{%2, %k0|%k0, %2}"
8560   [(set_attr "type" "alu")
8561    (set_attr "mode" "SI")])
8562
8563 (define_insn "*<code>qi_2_slp"
8564   [(set (reg FLAGS_REG)
8565         (compare (any_or:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8566                             (match_operand:QI 1 "general_operand" "qmn,qn"))
8567                  (const_int 0)))
8568    (set (strict_low_part (match_dup 0))
8569         (any_or:QI (match_dup 0) (match_dup 1)))]
8570   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8571    && ix86_match_ccmode (insn, CCNOmode)
8572    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8573   "<logic>{b}\t{%1, %0|%0, %1}"
8574   [(set_attr "type" "alu1")
8575    (set_attr "mode" "QI")])
8576
8577 (define_insn "*<code><mode>_3"
8578   [(set (reg FLAGS_REG)
8579         (compare (any_or:SWI
8580                   (match_operand:SWI 1 "nonimmediate_operand" "%0")
8581                   (match_operand:SWI 2 "<general_operand>" "<g>"))
8582                  (const_int 0)))
8583    (clobber (match_scratch:SWI 0 "=<r>"))]
8584   "ix86_match_ccmode (insn, CCNOmode)
8585    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8586   "<logic>{<imodesuffix>}\t{%2, %0|%0, %2}"
8587   [(set_attr "type" "alu")
8588    (set_attr "mode" "<MODE>")])
8589
8590 (define_insn "*<code>qi_ext_0"
8591   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8592                          (const_int 8)
8593                          (const_int 8))
8594         (any_or:SI
8595           (zero_extract:SI
8596             (match_operand 1 "ext_register_operand" "0")
8597             (const_int 8)
8598             (const_int 8))
8599           (match_operand 2 "const_int_operand" "n")))
8600    (clobber (reg:CC FLAGS_REG))]
8601   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8602   "<logic>{b}\t{%2, %h0|%h0, %2}"
8603   [(set_attr "type" "alu")
8604    (set_attr "length_immediate" "1")
8605    (set_attr "modrm" "1")
8606    (set_attr "mode" "QI")])
8607
8608 (define_insn "*<code>qi_ext_1"
8609   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
8610                          (const_int 8)
8611                          (const_int 8))
8612         (any_or:SI
8613           (zero_extract:SI
8614             (match_operand 1 "ext_register_operand" "0,0")
8615             (const_int 8)
8616             (const_int 8))
8617           (zero_extend:SI
8618             (match_operand:QI 2 "nonimmediate_x64nomem_operand" "Q,m"))))
8619    (clobber (reg:CC FLAGS_REG))]
8620   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8621   "<logic>{b}\t{%2, %h0|%h0, %2}"
8622   [(set_attr "isa" "*,nox64")
8623    (set_attr "type" "alu")
8624    (set_attr "length_immediate" "0")
8625    (set_attr "mode" "QI")])
8626
8627 (define_insn "*<code>qi_ext_2"
8628   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8629                          (const_int 8)
8630                          (const_int 8))
8631         (any_or:SI
8632           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
8633                            (const_int 8)
8634                            (const_int 8))
8635           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
8636                            (const_int 8)
8637                            (const_int 8))))
8638    (clobber (reg:CC FLAGS_REG))]
8639   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8640   "<logic>{b}\t{%h2, %h0|%h0, %h2}"
8641   [(set_attr "type" "alu")
8642    (set_attr "length_immediate" "0")
8643    (set_attr "mode" "QI")])
8644
8645 (define_split
8646   [(set (match_operand 0 "register_operand")
8647         (any_or (match_operand 1 "register_operand")
8648                 (match_operand 2 "const_int_operand")))
8649    (clobber (reg:CC FLAGS_REG))]
8650    "reload_completed
8651     && QI_REG_P (operands[0])
8652     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8653     && !(INTVAL (operands[2]) & ~(255 << 8))
8654     && GET_MODE (operands[0]) != QImode"
8655   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8656                    (any_or:SI (zero_extract:SI (match_dup 1)
8657                                                (const_int 8) (const_int 8))
8658                               (match_dup 2)))
8659               (clobber (reg:CC FLAGS_REG))])]
8660 {
8661   operands[0] = gen_lowpart (SImode, operands[0]);
8662   operands[1] = gen_lowpart (SImode, operands[1]);
8663   operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);
8664 })
8665
8666 ;; Since OR can be encoded with sign extended immediate, this is only
8667 ;; profitable when 7th bit is set.
8668 (define_split
8669   [(set (match_operand 0 "register_operand")
8670         (any_or (match_operand 1 "general_operand")
8671                 (match_operand 2 "const_int_operand")))
8672    (clobber (reg:CC FLAGS_REG))]
8673    "reload_completed
8674     && ANY_QI_REG_P (operands[0])
8675     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8676     && !(INTVAL (operands[2]) & ~255)
8677     && (INTVAL (operands[2]) & 128)
8678     && GET_MODE (operands[0]) != QImode"
8679   [(parallel [(set (strict_low_part (match_dup 0))
8680                    (any_or:QI (match_dup 1)
8681                               (match_dup 2)))
8682               (clobber (reg:CC FLAGS_REG))])]
8683 {
8684   operands[0] = gen_lowpart (QImode, operands[0]);
8685   operands[1] = gen_lowpart (QImode, operands[1]);
8686   operands[2] = gen_lowpart (QImode, operands[2]);
8687 })
8688
8689 (define_expand "xorqi_cc_ext_1"
8690   [(parallel [
8691      (set (reg:CCNO FLAGS_REG)
8692           (compare:CCNO
8693             (xor:SI
8694               (zero_extract:SI
8695                 (match_operand 1 "ext_register_operand")
8696                 (const_int 8)
8697                 (const_int 8))
8698               (match_operand:QI 2 "const_int_operand"))
8699             (const_int 0)))
8700      (set (zero_extract:SI (match_operand 0 "ext_register_operand")
8701                            (const_int 8)
8702                            (const_int 8))
8703           (xor:SI
8704             (zero_extract:SI
8705              (match_dup 1)
8706              (const_int 8)
8707              (const_int 8))
8708             (match_dup 2)))])])
8709
8710 (define_insn "*xorqi_cc_ext_1"
8711   [(set (reg FLAGS_REG)
8712         (compare
8713           (xor:SI
8714             (zero_extract:SI
8715               (match_operand 1 "ext_register_operand" "0,0")
8716               (const_int 8)
8717               (const_int 8))
8718             (match_operand:QI 2 "general_x64nomem_operand" "Qn,m"))
8719           (const_int 0)))
8720    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
8721                          (const_int 8)
8722                          (const_int 8))
8723         (xor:SI
8724           (zero_extract:SI
8725            (match_dup 1)
8726            (const_int 8)
8727            (const_int 8))
8728           (match_dup 2)))]
8729   "ix86_match_ccmode (insn, CCNOmode)"
8730   "xor{b}\t{%2, %h0|%h0, %2}"
8731   [(set_attr "isa" "*,nox64")
8732    (set_attr "type" "alu")
8733    (set_attr "modrm" "1")
8734    (set_attr "mode" "QI")])
8735 \f
8736 ;; Negation instructions
8737
8738 (define_expand "neg<mode>2"
8739   [(set (match_operand:SDWIM 0 "nonimmediate_operand")
8740         (neg:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand")))]
8741   ""
8742   "ix86_expand_unary_operator (NEG, <MODE>mode, operands); DONE;")
8743
8744 (define_insn_and_split "*neg<dwi>2_doubleword"
8745   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=ro")
8746         (neg:<DWI> (match_operand:<DWI> 1 "nonimmediate_operand" "0")))
8747    (clobber (reg:CC FLAGS_REG))]
8748   "ix86_unary_operator_ok (NEG, <DWI>mode, operands)"
8749   "#"
8750   "reload_completed"
8751   [(parallel
8752     [(set (reg:CCZ FLAGS_REG)
8753           (compare:CCZ (neg:DWIH (match_dup 1)) (const_int 0)))
8754      (set (match_dup 0) (neg:DWIH (match_dup 1)))])
8755    (parallel
8756     [(set (match_dup 2)
8757           (plus:DWIH (match_dup 3)
8758                      (plus:DWIH (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
8759                                 (const_int 0))))
8760      (clobber (reg:CC FLAGS_REG))])
8761    (parallel
8762     [(set (match_dup 2)
8763           (neg:DWIH (match_dup 2)))
8764      (clobber (reg:CC FLAGS_REG))])]
8765   "split_double_mode (<DWI>mode, &operands[0], 2, &operands[0], &operands[2]);")
8766
8767 (define_insn "*neg<mode>2_1"
8768   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8769         (neg:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")))
8770    (clobber (reg:CC FLAGS_REG))]
8771   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)"
8772   "neg{<imodesuffix>}\t%0"
8773   [(set_attr "type" "negnot")
8774    (set_attr "mode" "<MODE>")])
8775
8776 ;; Combine is quite creative about this pattern.
8777 (define_insn "*negsi2_1_zext"
8778   [(set (match_operand:DI 0 "register_operand" "=r")
8779         (lshiftrt:DI
8780           (neg:DI (ashift:DI (match_operand:DI 1 "register_operand" "0")
8781                              (const_int 32)))
8782         (const_int 32)))
8783    (clobber (reg:CC FLAGS_REG))]
8784   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
8785   "neg{l}\t%k0"
8786   [(set_attr "type" "negnot")
8787    (set_attr "mode" "SI")])
8788
8789 ;; The problem with neg is that it does not perform (compare x 0),
8790 ;; it really performs (compare 0 x), which leaves us with the zero
8791 ;; flag being the only useful item.
8792
8793 (define_insn "*neg<mode>2_cmpz"
8794   [(set (reg:CCZ FLAGS_REG)
8795         (compare:CCZ
8796           (neg:SWI (match_operand:SWI 1 "nonimmediate_operand" "0"))
8797                    (const_int 0)))
8798    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8799         (neg:SWI (match_dup 1)))]
8800   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)"
8801   "neg{<imodesuffix>}\t%0"
8802   [(set_attr "type" "negnot")
8803    (set_attr "mode" "<MODE>")])
8804
8805 (define_insn "*negsi2_cmpz_zext"
8806   [(set (reg:CCZ FLAGS_REG)
8807         (compare:CCZ
8808           (lshiftrt:DI
8809             (neg:DI (ashift:DI
8810                       (match_operand:DI 1 "register_operand" "0")
8811                       (const_int 32)))
8812             (const_int 32))
8813           (const_int 0)))
8814    (set (match_operand:DI 0 "register_operand" "=r")
8815         (lshiftrt:DI (neg:DI (ashift:DI (match_dup 1)
8816                                         (const_int 32)))
8817                      (const_int 32)))]
8818   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
8819   "neg{l}\t%k0"
8820   [(set_attr "type" "negnot")
8821    (set_attr "mode" "SI")])
8822
8823 ;; Negate with jump on overflow.
8824 (define_expand "negv<mode>3"
8825   [(parallel [(set (reg:CCO FLAGS_REG)
8826                    (ne:CCO (match_operand:SWI 1 "register_operand")
8827                            (match_dup 3)))
8828               (set (match_operand:SWI 0 "register_operand")
8829                    (neg:SWI (match_dup 1)))])
8830    (set (pc) (if_then_else
8831                (eq (reg:CCO FLAGS_REG) (const_int 0))
8832                (label_ref (match_operand 2))
8833                (pc)))]
8834   ""
8835 {
8836   operands[3]
8837     = gen_int_mode (HOST_WIDE_INT_1U << (GET_MODE_BITSIZE (<MODE>mode) - 1),
8838                     <MODE>mode);
8839 })
8840
8841 (define_insn "*negv<mode>3"
8842   [(set (reg:CCO FLAGS_REG)
8843         (ne:CCO (match_operand:SWI 1 "nonimmediate_operand" "0")
8844                 (match_operand:SWI 2 "const_int_operand")))
8845    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8846         (neg:SWI (match_dup 1)))]
8847   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)
8848    && mode_signbit_p (<MODE>mode, operands[2])"
8849   "neg{<imodesuffix>}\t%0"
8850   [(set_attr "type" "negnot")
8851    (set_attr "mode" "<MODE>")])
8852
8853 ;; Changing of sign for FP values is doable using integer unit too.
8854
8855 (define_expand "<code><mode>2"
8856   [(set (match_operand:X87MODEF 0 "register_operand")
8857         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand")))]
8858   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
8859   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
8860
8861 (define_insn "*absneg<mode>2_mixed"
8862   [(set (match_operand:MODEF 0 "register_operand" "=x,x,f,!r")
8863         (match_operator:MODEF 3 "absneg_operator"
8864           [(match_operand:MODEF 1 "register_operand" "0,x,0,0")]))
8865    (use (match_operand:<ssevecmode> 2 "nonimmediate_operand" "xm,0,X,X"))
8866    (clobber (reg:CC FLAGS_REG))]
8867   "TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (<MODE>mode)"
8868   "#")
8869
8870 (define_insn "*absneg<mode>2_sse"
8871   [(set (match_operand:MODEF 0 "register_operand" "=x,x,!r")
8872         (match_operator:MODEF 3 "absneg_operator"
8873           [(match_operand:MODEF 1 "register_operand" "0 ,x,0")]))
8874    (use (match_operand:<ssevecmode> 2 "register_operand" "xm,0,X"))
8875    (clobber (reg:CC FLAGS_REG))]
8876   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
8877   "#")
8878
8879 (define_insn "*absneg<mode>2_i387"
8880   [(set (match_operand:X87MODEF 0 "register_operand" "=f,!r")
8881         (match_operator:X87MODEF 3 "absneg_operator"
8882           [(match_operand:X87MODEF 1 "register_operand" "0,0")]))
8883    (use (match_operand 2))
8884    (clobber (reg:CC FLAGS_REG))]
8885   "TARGET_80387 && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
8886   "#")
8887
8888 (define_expand "<code>tf2"
8889   [(set (match_operand:TF 0 "register_operand")
8890         (absneg:TF (match_operand:TF 1 "register_operand")))]
8891   "TARGET_SSE"
8892   "ix86_expand_fp_absneg_operator (<CODE>, TFmode, operands); DONE;")
8893
8894 (define_insn "*absnegtf2_sse"
8895   [(set (match_operand:TF 0 "register_operand" "=x,x")
8896         (match_operator:TF 3 "absneg_operator"
8897           [(match_operand:TF 1 "register_operand" "0,x")]))
8898    (use (match_operand:TF 2 "nonimmediate_operand" "xm,0"))
8899    (clobber (reg:CC FLAGS_REG))]
8900   "TARGET_SSE"
8901   "#")
8902
8903 ;; Splitters for fp abs and neg.
8904
8905 (define_split
8906   [(set (match_operand 0 "fp_register_operand")
8907         (match_operator 1 "absneg_operator" [(match_dup 0)]))
8908    (use (match_operand 2))
8909    (clobber (reg:CC FLAGS_REG))]
8910   "reload_completed"
8911   [(set (match_dup 0) (match_op_dup 1 [(match_dup 0)]))])
8912
8913 (define_split
8914   [(set (match_operand 0 "register_operand")
8915         (match_operator 3 "absneg_operator"
8916           [(match_operand 1 "register_operand")]))
8917    (use (match_operand 2 "nonimmediate_operand"))
8918    (clobber (reg:CC FLAGS_REG))]
8919   "reload_completed && SSE_REG_P (operands[0])"
8920   [(set (match_dup 0) (match_dup 3))]
8921 {
8922   machine_mode mode = GET_MODE (operands[0]);
8923   machine_mode vmode = GET_MODE (operands[2]);
8924   rtx tmp;
8925
8926   operands[0] = simplify_gen_subreg (vmode, operands[0], mode, 0);
8927   operands[1] = simplify_gen_subreg (vmode, operands[1], mode, 0);
8928   if (operands_match_p (operands[0], operands[2]))
8929     std::swap (operands[1], operands[2]);
8930   if (GET_CODE (operands[3]) == ABS)
8931     tmp = gen_rtx_AND (vmode, operands[1], operands[2]);
8932   else
8933     tmp = gen_rtx_XOR (vmode, operands[1], operands[2]);
8934   operands[3] = tmp;
8935 })
8936
8937 (define_split
8938   [(set (match_operand:SF 0 "register_operand")
8939         (match_operator:SF 1 "absneg_operator" [(match_dup 0)]))
8940    (use (match_operand:V4SF 2))
8941    (clobber (reg:CC FLAGS_REG))]
8942   "reload_completed"
8943   [(parallel [(set (match_dup 0) (match_dup 1))
8944               (clobber (reg:CC FLAGS_REG))])]
8945 {
8946   rtx tmp;
8947   operands[0] = gen_lowpart (SImode, operands[0]);
8948   if (GET_CODE (operands[1]) == ABS)
8949     {
8950       tmp = gen_int_mode (0x7fffffff, SImode);
8951       tmp = gen_rtx_AND (SImode, operands[0], tmp);
8952     }
8953   else
8954     {
8955       tmp = gen_int_mode (0x80000000, SImode);
8956       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8957     }
8958   operands[1] = tmp;
8959 })
8960
8961 (define_split
8962   [(set (match_operand:DF 0 "register_operand")
8963         (match_operator:DF 1 "absneg_operator" [(match_dup 0)]))
8964    (use (match_operand 2))
8965    (clobber (reg:CC FLAGS_REG))]
8966   "reload_completed"
8967   [(parallel [(set (match_dup 0) (match_dup 1))
8968               (clobber (reg:CC FLAGS_REG))])]
8969 {
8970   rtx tmp;
8971   if (TARGET_64BIT)
8972     {
8973       tmp = gen_lowpart (DImode, operands[0]);
8974       tmp = gen_rtx_ZERO_EXTRACT (DImode, tmp, const1_rtx, GEN_INT (63));
8975       operands[0] = tmp;
8976
8977       if (GET_CODE (operands[1]) == ABS)
8978         tmp = const0_rtx;
8979       else
8980         tmp = gen_rtx_NOT (DImode, tmp);
8981     }
8982   else
8983     {
8984       operands[0] = gen_highpart (SImode, operands[0]);
8985       if (GET_CODE (operands[1]) == ABS)
8986         {
8987           tmp = gen_int_mode (0x7fffffff, SImode);
8988           tmp = gen_rtx_AND (SImode, operands[0], tmp);
8989         }
8990       else
8991         {
8992           tmp = gen_int_mode (0x80000000, SImode);
8993           tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8994         }
8995     }
8996   operands[1] = tmp;
8997 })
8998
8999 (define_split
9000   [(set (match_operand:XF 0 "register_operand")
9001         (match_operator:XF 1 "absneg_operator" [(match_dup 0)]))
9002    (use (match_operand 2))
9003    (clobber (reg:CC FLAGS_REG))]
9004   "reload_completed"
9005   [(parallel [(set (match_dup 0) (match_dup 1))
9006               (clobber (reg:CC FLAGS_REG))])]
9007 {
9008   rtx tmp;
9009   operands[0] = gen_rtx_REG (SImode,
9010                              true_regnum (operands[0])
9011                              + (TARGET_64BIT ? 1 : 2));
9012   if (GET_CODE (operands[1]) == ABS)
9013     {
9014       tmp = GEN_INT (0x7fff);
9015       tmp = gen_rtx_AND (SImode, operands[0], tmp);
9016     }
9017   else
9018     {
9019       tmp = GEN_INT (0x8000);
9020       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
9021     }
9022   operands[1] = tmp;
9023 })
9024
9025 ;; Conditionalize these after reload. If they match before reload, we
9026 ;; lose the clobber and ability to use integer instructions.
9027
9028 (define_insn "*<code><mode>2_1"
9029   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
9030         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand" "0")))]
9031   "TARGET_80387
9032    && (reload_completed
9033        || !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
9034   "f<absneg_mnemonic>"
9035   [(set_attr "type" "fsgn")
9036    (set_attr "mode" "<MODE>")])
9037
9038 (define_insn "*<code>extendsfdf2"
9039   [(set (match_operand:DF 0 "register_operand" "=f")
9040         (absneg:DF (float_extend:DF
9041                      (match_operand:SF 1 "register_operand" "0"))))]
9042   "TARGET_80387 && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)"
9043   "f<absneg_mnemonic>"
9044   [(set_attr "type" "fsgn")
9045    (set_attr "mode" "DF")])
9046
9047 (define_insn "*<code>extendsfxf2"
9048   [(set (match_operand:XF 0 "register_operand" "=f")
9049         (absneg:XF (float_extend:XF
9050                      (match_operand:SF 1 "register_operand" "0"))))]
9051   "TARGET_80387"
9052   "f<absneg_mnemonic>"
9053   [(set_attr "type" "fsgn")
9054    (set_attr "mode" "XF")])
9055
9056 (define_insn "*<code>extenddfxf2"
9057   [(set (match_operand:XF 0 "register_operand" "=f")
9058         (absneg:XF (float_extend:XF
9059                      (match_operand:DF 1 "register_operand" "0"))))]
9060   "TARGET_80387"
9061   "f<absneg_mnemonic>"
9062   [(set_attr "type" "fsgn")
9063    (set_attr "mode" "XF")])
9064
9065 ;; Copysign instructions
9066
9067 (define_mode_iterator CSGNMODE [SF DF TF])
9068 (define_mode_attr CSGNVMODE [(SF "V4SF") (DF "V2DF") (TF "TF")])
9069
9070 (define_expand "copysign<mode>3"
9071   [(match_operand:CSGNMODE 0 "register_operand")
9072    (match_operand:CSGNMODE 1 "nonmemory_operand")
9073    (match_operand:CSGNMODE 2 "register_operand")]
9074   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9075    || (TARGET_SSE && (<MODE>mode == TFmode))"
9076   "ix86_expand_copysign (operands); DONE;")
9077
9078 (define_insn_and_split "copysign<mode>3_const"
9079   [(set (match_operand:CSGNMODE 0 "register_operand" "=x")
9080         (unspec:CSGNMODE
9081           [(match_operand:<CSGNVMODE> 1 "vector_move_operand" "xmC")
9082            (match_operand:CSGNMODE 2 "register_operand" "0")
9083            (match_operand:<CSGNVMODE> 3 "nonimmediate_operand" "xm")]
9084           UNSPEC_COPYSIGN))]
9085   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9086    || (TARGET_SSE && (<MODE>mode == TFmode))"
9087   "#"
9088   "&& reload_completed"
9089   [(const_int 0)]
9090   "ix86_split_copysign_const (operands); DONE;")
9091
9092 (define_insn "copysign<mode>3_var"
9093   [(set (match_operand:CSGNMODE 0 "register_operand" "=x,x,x,x,x")
9094         (unspec:CSGNMODE
9095           [(match_operand:CSGNMODE 2 "register_operand" "x,0,0,x,x")
9096            (match_operand:CSGNMODE 3 "register_operand" "1,1,x,1,x")
9097            (match_operand:<CSGNVMODE> 4 "nonimmediate_operand" "X,xm,xm,0,0")
9098            (match_operand:<CSGNVMODE> 5 "nonimmediate_operand" "0,xm,1,xm,1")]
9099           UNSPEC_COPYSIGN))
9100    (clobber (match_scratch:<CSGNVMODE> 1 "=x,x,x,x,x"))]
9101   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9102    || (TARGET_SSE && (<MODE>mode == TFmode))"
9103   "#")
9104
9105 (define_split
9106   [(set (match_operand:CSGNMODE 0 "register_operand")
9107         (unspec:CSGNMODE
9108           [(match_operand:CSGNMODE 2 "register_operand")
9109            (match_operand:CSGNMODE 3 "register_operand")
9110            (match_operand:<CSGNVMODE> 4)
9111            (match_operand:<CSGNVMODE> 5)]
9112           UNSPEC_COPYSIGN))
9113    (clobber (match_scratch:<CSGNVMODE> 1))]
9114   "((SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9115     || (TARGET_SSE && (<MODE>mode == TFmode)))
9116    && reload_completed"
9117   [(const_int 0)]
9118   "ix86_split_copysign_var (operands); DONE;")
9119 \f
9120 ;; One complement instructions
9121
9122 (define_expand "one_cmpl<mode>2"
9123   [(set (match_operand:SWIM 0 "nonimmediate_operand")
9124         (not:SWIM (match_operand:SWIM 1 "nonimmediate_operand")))]
9125   ""
9126   "ix86_expand_unary_operator (NOT, <MODE>mode, operands); DONE;")
9127
9128 (define_insn "*one_cmpl<mode>2_1"
9129   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,k")
9130         (not:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,k")))]
9131   "ix86_unary_operator_ok (NOT, <MODE>mode, operands)"
9132   "@
9133    not{<imodesuffix>}\t%0
9134    knot<mskmodesuffix>\t{%1, %0|%0, %1}"
9135   [(set_attr "isa" "*,avx512bw")
9136    (set_attr "type" "negnot,msklog")
9137    (set_attr "prefix" "*,vex")
9138    (set_attr "mode" "<MODE>")])
9139
9140 (define_insn "*one_cmplhi2_1"
9141   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,!k")
9142         (not:HI (match_operand:HI 1 "nonimmediate_operand" "0,k")))]
9143   "ix86_unary_operator_ok (NOT, HImode, operands)"
9144   "@
9145    not{w}\t%0
9146    knotw\t{%1, %0|%0, %1}"
9147   [(set_attr "isa" "*,avx512f")
9148    (set_attr "type" "negnot,msklog")
9149    (set_attr "prefix" "*,vex")
9150    (set_attr "mode" "HI")])
9151
9152 ;; %%% Potential partial reg stall on alternative 1.  What to do?
9153 (define_insn "*one_cmplqi2_1"
9154   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,!k")
9155         (not:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,k")))]
9156   "ix86_unary_operator_ok (NOT, QImode, operands)"
9157 {
9158   switch (which_alternative)
9159     {
9160     case 0:
9161       return "not{b}\t%0";
9162     case 1:
9163       return "not{l}\t%k0";
9164     case 2:
9165       if (TARGET_AVX512DQ)
9166         return "knotb\t{%1, %0|%0, %1}";
9167       return "knotw\t{%1, %0|%0, %1}";
9168     default:
9169       gcc_unreachable ();
9170     }
9171 }
9172   [(set_attr "isa" "*,*,avx512f")
9173    (set_attr "type" "negnot,negnot,msklog")
9174    (set_attr "prefix" "*,*,vex")
9175    (set_attr "mode" "QI,SI,QI")])
9176
9177 ;; ??? Currently never generated - xor is used instead.
9178 (define_insn "*one_cmplsi2_1_zext"
9179   [(set (match_operand:DI 0 "register_operand" "=r")
9180         (zero_extend:DI
9181           (not:SI (match_operand:SI 1 "register_operand" "0"))))]
9182   "TARGET_64BIT && ix86_unary_operator_ok (NOT, SImode, operands)"
9183   "not{l}\t%k0"
9184   [(set_attr "type" "negnot")
9185    (set_attr "mode" "SI")])
9186
9187 (define_insn "*one_cmpl<mode>2_2"
9188   [(set (reg FLAGS_REG)
9189         (compare (not:SWI (match_operand:SWI 1 "nonimmediate_operand" "0"))
9190                  (const_int 0)))
9191    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
9192         (not:SWI (match_dup 1)))]
9193   "ix86_match_ccmode (insn, CCNOmode)
9194    && ix86_unary_operator_ok (NOT, <MODE>mode, operands)"
9195   "#"
9196   [(set_attr "type" "alu1")
9197    (set_attr "mode" "<MODE>")])
9198
9199 (define_split
9200   [(set (match_operand 0 "flags_reg_operand")
9201         (match_operator 2 "compare_operator"
9202           [(not:SWI (match_operand:SWI 3 "nonimmediate_operand"))
9203            (const_int 0)]))
9204    (set (match_operand:SWI 1 "nonimmediate_operand")
9205         (not:SWI (match_dup 3)))]
9206   "ix86_match_ccmode (insn, CCNOmode)"
9207   [(parallel [(set (match_dup 0)
9208                    (match_op_dup 2 [(xor:SWI (match_dup 3) (const_int -1))
9209                                     (const_int 0)]))
9210               (set (match_dup 1)
9211                    (xor:SWI (match_dup 3) (const_int -1)))])])
9212
9213 ;; ??? Currently never generated - xor is used instead.
9214 (define_insn "*one_cmplsi2_2_zext"
9215   [(set (reg FLAGS_REG)
9216         (compare (not:SI (match_operand:SI 1 "register_operand" "0"))
9217                  (const_int 0)))
9218    (set (match_operand:DI 0 "register_operand" "=r")
9219         (zero_extend:DI (not:SI (match_dup 1))))]
9220   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9221    && ix86_unary_operator_ok (NOT, SImode, operands)"
9222   "#"
9223   [(set_attr "type" "alu1")
9224    (set_attr "mode" "SI")])
9225
9226 (define_split
9227   [(set (match_operand 0 "flags_reg_operand")
9228         (match_operator 2 "compare_operator"
9229           [(not:SI (match_operand:SI 3 "register_operand"))
9230            (const_int 0)]))
9231    (set (match_operand:DI 1 "register_operand")
9232         (zero_extend:DI (not:SI (match_dup 3))))]
9233   "ix86_match_ccmode (insn, CCNOmode)"
9234   [(parallel [(set (match_dup 0)
9235                    (match_op_dup 2 [(xor:SI (match_dup 3) (const_int -1))
9236                                     (const_int 0)]))
9237               (set (match_dup 1)
9238                    (zero_extend:DI (xor:SI (match_dup 3) (const_int -1))))])])
9239 \f
9240 ;; Shift instructions
9241
9242 ;; DImode shifts are implemented using the i386 "shift double" opcode,
9243 ;; which is written as "sh[lr]d[lw] imm,reg,reg/mem".  If the shift count
9244 ;; is variable, then the count is in %cl and the "imm" operand is dropped
9245 ;; from the assembler input.
9246 ;;
9247 ;; This instruction shifts the target reg/mem as usual, but instead of
9248 ;; shifting in zeros, bits are shifted in from reg operand.  If the insn
9249 ;; is a left shift double, bits are taken from the high order bits of
9250 ;; reg, else if the insn is a shift right double, bits are taken from the
9251 ;; low order bits of reg.  So if %eax is "1234" and %edx is "5678",
9252 ;; "shldl $8,%edx,%eax" leaves %edx unchanged and sets %eax to "2345".
9253 ;;
9254 ;; Since sh[lr]d does not change the `reg' operand, that is done
9255 ;; separately, making all shifts emit pairs of shift double and normal
9256 ;; shift.  Since sh[lr]d does not shift more than 31 bits, and we wish to
9257 ;; support a 63 bit shift, each shift where the count is in a reg expands
9258 ;; to a pair of shifts, a branch, a shift by 32 and a label.
9259 ;;
9260 ;; If the shift count is a constant, we need never emit more than one
9261 ;; shift pair, instead using moves and sign extension for counts greater
9262 ;; than 31.
9263
9264 (define_expand "ashl<mode>3"
9265   [(set (match_operand:SDWIM 0 "<shift_operand>")
9266         (ashift:SDWIM (match_operand:SDWIM 1 "<ashl_input_operand>")
9267                       (match_operand:QI 2 "nonmemory_operand")))]
9268   ""
9269   "ix86_expand_binary_operator (ASHIFT, <MODE>mode, operands); DONE;")
9270
9271 (define_insn "*ashl<mode>3_doubleword"
9272   [(set (match_operand:DWI 0 "register_operand" "=&r,r")
9273         (ashift:DWI (match_operand:DWI 1 "reg_or_pm1_operand" "n,0")
9274                     (match_operand:QI 2 "nonmemory_operand" "<S>c,<S>c")))
9275    (clobber (reg:CC FLAGS_REG))]
9276   ""
9277   "#"
9278   [(set_attr "type" "multi")])
9279
9280 (define_split
9281   [(set (match_operand:DWI 0 "register_operand")
9282         (ashift:DWI (match_operand:DWI 1 "nonmemory_operand")
9283                     (match_operand:QI 2 "nonmemory_operand")))
9284    (clobber (reg:CC FLAGS_REG))]
9285   "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
9286   [(const_int 0)]
9287   "ix86_split_ashl (operands, NULL_RTX, <MODE>mode); DONE;")
9288
9289 ;; By default we don't ask for a scratch register, because when DWImode
9290 ;; values are manipulated, registers are already at a premium.  But if
9291 ;; we have one handy, we won't turn it away.
9292
9293 (define_peephole2
9294   [(match_scratch:DWIH 3 "r")
9295    (parallel [(set (match_operand:<DWI> 0 "register_operand")
9296                    (ashift:<DWI>
9297                      (match_operand:<DWI> 1 "nonmemory_operand")
9298                      (match_operand:QI 2 "nonmemory_operand")))
9299               (clobber (reg:CC FLAGS_REG))])
9300    (match_dup 3)]
9301   "TARGET_CMOVE"
9302   [(const_int 0)]
9303   "ix86_split_ashl (operands, operands[3], <DWI>mode); DONE;")
9304
9305 (define_insn "x86_64_shld"
9306   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
9307         (ior:DI (ashift:DI (match_dup 0)
9308                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
9309                 (lshiftrt:DI (match_operand:DI 1 "register_operand" "r")
9310                   (minus:QI (const_int 64) (match_dup 2)))))
9311    (clobber (reg:CC FLAGS_REG))]
9312   "TARGET_64BIT"
9313   "shld{q}\t{%s2%1, %0|%0, %1, %2}"
9314   [(set_attr "type" "ishift")
9315    (set_attr "prefix_0f" "1")
9316    (set_attr "mode" "DI")
9317    (set_attr "athlon_decode" "vector")
9318    (set_attr "amdfam10_decode" "vector")
9319    (set_attr "bdver1_decode" "vector")])
9320
9321 (define_insn "x86_shld"
9322   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
9323         (ior:SI (ashift:SI (match_dup 0)
9324                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
9325                 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
9326                   (minus:QI (const_int 32) (match_dup 2)))))
9327    (clobber (reg:CC FLAGS_REG))]
9328   ""
9329   "shld{l}\t{%s2%1, %0|%0, %1, %2}"
9330   [(set_attr "type" "ishift")
9331    (set_attr "prefix_0f" "1")
9332    (set_attr "mode" "SI")
9333    (set_attr "pent_pair" "np")
9334    (set_attr "athlon_decode" "vector")
9335    (set_attr "amdfam10_decode" "vector")
9336    (set_attr "bdver1_decode" "vector")])
9337
9338 (define_expand "x86_shift<mode>_adj_1"
9339   [(set (reg:CCZ FLAGS_REG)
9340         (compare:CCZ (and:QI (match_operand:QI 2 "register_operand")
9341                              (match_dup 4))
9342                      (const_int 0)))
9343    (set (match_operand:SWI48 0 "register_operand")
9344         (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
9345                             (match_operand:SWI48 1 "register_operand")
9346                             (match_dup 0)))
9347    (set (match_dup 1)
9348         (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
9349                             (match_operand:SWI48 3 "register_operand")
9350                             (match_dup 1)))]
9351   "TARGET_CMOVE"
9352   "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
9353
9354 (define_expand "x86_shift<mode>_adj_2"
9355   [(use (match_operand:SWI48 0 "register_operand"))
9356    (use (match_operand:SWI48 1 "register_operand"))
9357    (use (match_operand:QI 2 "register_operand"))]
9358   ""
9359 {
9360   rtx_code_label *label = gen_label_rtx ();
9361   rtx tmp;
9362
9363   emit_insn (gen_testqi_ccz_1 (operands[2],
9364                                GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
9365
9366   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
9367   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
9368   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
9369                               gen_rtx_LABEL_REF (VOIDmode, label),
9370                               pc_rtx);
9371   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
9372   JUMP_LABEL (tmp) = label;
9373
9374   emit_move_insn (operands[0], operands[1]);
9375   ix86_expand_clear (operands[1]);
9376
9377   emit_label (label);
9378   LABEL_NUSES (label) = 1;
9379
9380   DONE;
9381 })
9382
9383 ;; Avoid useless masking of count operand.
9384 (define_insn "*ashl<mode>3_mask"
9385   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
9386         (ashift:SWI48
9387           (match_operand:SWI48 1 "nonimmediate_operand" "0")
9388           (subreg:QI
9389             (and:SI
9390               (match_operand:SI 2 "register_operand" "c")
9391               (match_operand:SI 3 "const_int_operand" "n")) 0)))
9392    (clobber (reg:CC FLAGS_REG))]
9393   "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)
9394    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
9395       == GET_MODE_BITSIZE (<MODE>mode)-1"
9396 {
9397   return "sal{<imodesuffix>}\t{%b2, %0|%0, %b2}";
9398 }
9399   [(set_attr "type" "ishift")
9400    (set_attr "mode" "<MODE>")])
9401
9402 (define_insn "*bmi2_ashl<mode>3_1"
9403   [(set (match_operand:SWI48 0 "register_operand" "=r")
9404         (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm")
9405                       (match_operand:SWI48 2 "register_operand" "r")))]
9406   "TARGET_BMI2"
9407   "shlx\t{%2, %1, %0|%0, %1, %2}"
9408   [(set_attr "type" "ishiftx")
9409    (set_attr "mode" "<MODE>")])
9410
9411 (define_insn "*ashl<mode>3_1"
9412   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r,r")
9413         (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,l,rm")
9414                       (match_operand:QI 2 "nonmemory_operand" "c<S>,M,r")))
9415    (clobber (reg:CC FLAGS_REG))]
9416   "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
9417 {
9418   switch (get_attr_type (insn))
9419     {
9420     case TYPE_LEA:
9421     case TYPE_ISHIFTX:
9422       return "#";
9423
9424     case TYPE_ALU:
9425       gcc_assert (operands[2] == const1_rtx);
9426       gcc_assert (rtx_equal_p (operands[0], operands[1]));
9427       return "add{<imodesuffix>}\t%0, %0";
9428
9429     default:
9430       if (operands[2] == const1_rtx
9431           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9432         return "sal{<imodesuffix>}\t%0";
9433       else
9434         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9435     }
9436 }
9437   [(set_attr "isa" "*,*,bmi2")
9438    (set (attr "type")
9439      (cond [(eq_attr "alternative" "1")
9440               (const_string "lea")
9441             (eq_attr "alternative" "2")
9442               (const_string "ishiftx")
9443             (and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9444                       (match_operand 0 "register_operand"))
9445                  (match_operand 2 "const1_operand"))
9446               (const_string "alu")
9447            ]
9448            (const_string "ishift")))
9449    (set (attr "length_immediate")
9450      (if_then_else
9451        (ior (eq_attr "type" "alu")
9452             (and (eq_attr "type" "ishift")
9453                  (and (match_operand 2 "const1_operand")
9454                       (ior (match_test "TARGET_SHIFT1")
9455                            (match_test "optimize_function_for_size_p (cfun)")))))
9456        (const_string "0")
9457        (const_string "*")))
9458    (set_attr "mode" "<MODE>")])
9459
9460 ;; Convert shift to the shiftx pattern to avoid flags dependency.
9461 (define_split
9462   [(set (match_operand:SWI48 0 "register_operand")
9463         (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
9464                       (match_operand:QI 2 "register_operand")))
9465    (clobber (reg:CC FLAGS_REG))]
9466   "TARGET_BMI2 && reload_completed"
9467   [(set (match_dup 0)
9468         (ashift:SWI48 (match_dup 1) (match_dup 2)))]
9469   "operands[2] = gen_lowpart (<MODE>mode, operands[2]);")
9470
9471 (define_insn "*bmi2_ashlsi3_1_zext"
9472   [(set (match_operand:DI 0 "register_operand" "=r")
9473         (zero_extend:DI
9474           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "rm")
9475                      (match_operand:SI 2 "register_operand" "r"))))]
9476   "TARGET_64BIT && TARGET_BMI2"
9477   "shlx\t{%2, %1, %k0|%k0, %1, %2}"
9478   [(set_attr "type" "ishiftx")
9479    (set_attr "mode" "SI")])
9480
9481 (define_insn "*ashlsi3_1_zext"
9482   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
9483         (zero_extend:DI
9484           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0,l,rm")
9485                      (match_operand:QI 2 "nonmemory_operand" "cI,M,r"))))
9486    (clobber (reg:CC FLAGS_REG))]
9487   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
9488 {
9489   switch (get_attr_type (insn))
9490     {
9491     case TYPE_LEA:
9492     case TYPE_ISHIFTX:
9493       return "#";
9494
9495     case TYPE_ALU:
9496       gcc_assert (operands[2] == const1_rtx);
9497       return "add{l}\t%k0, %k0";
9498
9499     default:
9500       if (operands[2] == const1_rtx
9501           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9502         return "sal{l}\t%k0";
9503       else
9504         return "sal{l}\t{%2, %k0|%k0, %2}";
9505     }
9506 }
9507   [(set_attr "isa" "*,*,bmi2")
9508    (set (attr "type")
9509      (cond [(eq_attr "alternative" "1")
9510               (const_string "lea")
9511             (eq_attr "alternative" "2")
9512               (const_string "ishiftx")
9513             (and (match_test "TARGET_DOUBLE_WITH_ADD")
9514                  (match_operand 2 "const1_operand"))
9515               (const_string "alu")
9516            ]
9517            (const_string "ishift")))
9518    (set (attr "length_immediate")
9519      (if_then_else
9520        (ior (eq_attr "type" "alu")
9521             (and (eq_attr "type" "ishift")
9522                  (and (match_operand 2 "const1_operand")
9523                       (ior (match_test "TARGET_SHIFT1")
9524                            (match_test "optimize_function_for_size_p (cfun)")))))
9525        (const_string "0")
9526        (const_string "*")))
9527    (set_attr "mode" "SI")])
9528
9529 ;; Convert shift to the shiftx pattern to avoid flags dependency.
9530 (define_split
9531   [(set (match_operand:DI 0 "register_operand")
9532         (zero_extend:DI
9533           (ashift:SI (match_operand:SI 1 "nonimmediate_operand")
9534                      (match_operand:QI 2 "register_operand"))))
9535    (clobber (reg:CC FLAGS_REG))]
9536   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
9537   [(set (match_dup 0)
9538         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
9539   "operands[2] = gen_lowpart (SImode, operands[2]);")
9540
9541 (define_insn "*ashlhi3_1"
9542   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,Yp")
9543         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,l")
9544                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
9545    (clobber (reg:CC FLAGS_REG))]
9546   "ix86_binary_operator_ok (ASHIFT, HImode, operands)"
9547 {
9548   switch (get_attr_type (insn))
9549     {
9550     case TYPE_LEA:
9551       return "#";
9552
9553     case TYPE_ALU:
9554       gcc_assert (operands[2] == const1_rtx);
9555       return "add{w}\t%0, %0";
9556
9557     default:
9558       if (operands[2] == const1_rtx
9559           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9560         return "sal{w}\t%0";
9561       else
9562         return "sal{w}\t{%2, %0|%0, %2}";
9563     }
9564 }
9565   [(set (attr "type")
9566      (cond [(eq_attr "alternative" "1")
9567               (const_string "lea")
9568             (and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9569                       (match_operand 0 "register_operand"))
9570                  (match_operand 2 "const1_operand"))
9571               (const_string "alu")
9572            ]
9573            (const_string "ishift")))
9574    (set (attr "length_immediate")
9575      (if_then_else
9576        (ior (eq_attr "type" "alu")
9577             (and (eq_attr "type" "ishift")
9578                  (and (match_operand 2 "const1_operand")
9579                       (ior (match_test "TARGET_SHIFT1")
9580                            (match_test "optimize_function_for_size_p (cfun)")))))
9581        (const_string "0")
9582        (const_string "*")))
9583    (set_attr "mode" "HI,SI")])
9584
9585 ;; %%% Potential partial reg stall on alternative 1.  What to do?
9586 (define_insn "*ashlqi3_1"
9587   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,Yp")
9588         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,l")
9589                    (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
9590    (clobber (reg:CC FLAGS_REG))]
9591   "ix86_binary_operator_ok (ASHIFT, QImode, operands)"
9592 {
9593   switch (get_attr_type (insn))
9594     {
9595     case TYPE_LEA:
9596       return "#";
9597
9598     case TYPE_ALU:
9599       gcc_assert (operands[2] == const1_rtx);
9600       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
9601         return "add{l}\t%k0, %k0";
9602       else
9603         return "add{b}\t%0, %0";
9604
9605     default:
9606       if (operands[2] == const1_rtx
9607           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9608         {
9609           if (get_attr_mode (insn) == MODE_SI)
9610             return "sal{l}\t%k0";
9611           else
9612             return "sal{b}\t%0";
9613         }
9614       else
9615         {
9616           if (get_attr_mode (insn) == MODE_SI)
9617             return "sal{l}\t{%2, %k0|%k0, %2}";
9618           else
9619             return "sal{b}\t{%2, %0|%0, %2}";
9620         }
9621     }
9622 }
9623   [(set (attr "type")
9624      (cond [(eq_attr "alternative" "2")
9625               (const_string "lea")
9626             (and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9627                       (match_operand 0 "register_operand"))
9628                  (match_operand 2 "const1_operand"))
9629               (const_string "alu")
9630            ]
9631            (const_string "ishift")))
9632    (set (attr "length_immediate")
9633      (if_then_else
9634        (ior (eq_attr "type" "alu")
9635             (and (eq_attr "type" "ishift")
9636                  (and (match_operand 2 "const1_operand")
9637                       (ior (match_test "TARGET_SHIFT1")
9638                            (match_test "optimize_function_for_size_p (cfun)")))))
9639        (const_string "0")
9640        (const_string "*")))
9641    (set_attr "mode" "QI,SI,SI")])
9642
9643 (define_insn "*ashlqi3_1_slp"
9644   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
9645         (ashift:QI (match_dup 0)
9646                    (match_operand:QI 1 "nonmemory_operand" "cI")))
9647    (clobber (reg:CC FLAGS_REG))]
9648   "(optimize_function_for_size_p (cfun)
9649     || !TARGET_PARTIAL_FLAG_REG_STALL
9650     || (operands[1] == const1_rtx
9651         && (TARGET_SHIFT1
9652             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))"
9653 {
9654   switch (get_attr_type (insn))
9655     {
9656     case TYPE_ALU:
9657       gcc_assert (operands[1] == const1_rtx);
9658       return "add{b}\t%0, %0";
9659
9660     default:
9661       if (operands[1] == const1_rtx
9662           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9663         return "sal{b}\t%0";
9664       else
9665         return "sal{b}\t{%1, %0|%0, %1}";
9666     }
9667 }
9668   [(set (attr "type")
9669      (cond [(and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9670                       (match_operand 0 "register_operand"))
9671                  (match_operand 1 "const1_operand"))
9672               (const_string "alu")
9673            ]
9674            (const_string "ishift1")))
9675    (set (attr "length_immediate")
9676      (if_then_else
9677        (ior (eq_attr "type" "alu")
9678             (and (eq_attr "type" "ishift1")
9679                  (and (match_operand 1 "const1_operand")
9680                       (ior (match_test "TARGET_SHIFT1")
9681                            (match_test "optimize_function_for_size_p (cfun)")))))
9682        (const_string "0")
9683        (const_string "*")))
9684    (set_attr "mode" "QI")])
9685
9686 ;; Convert ashift to the lea pattern to avoid flags dependency.
9687 (define_split
9688   [(set (match_operand 0 "register_operand")
9689         (ashift (match_operand 1 "index_register_operand")
9690                 (match_operand:QI 2 "const_int_operand")))
9691    (clobber (reg:CC FLAGS_REG))]
9692   "GET_MODE (operands[0]) == GET_MODE (operands[1])
9693    && reload_completed
9694    && true_regnum (operands[0]) != true_regnum (operands[1])"
9695   [(const_int 0)]
9696 {
9697   machine_mode mode = GET_MODE (operands[0]);
9698   rtx pat;
9699
9700   if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
9701     { 
9702       mode = SImode; 
9703       operands[0] = gen_lowpart (mode, operands[0]);
9704       operands[1] = gen_lowpart (mode, operands[1]);
9705     }
9706
9707   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), mode);
9708
9709   pat = gen_rtx_MULT (mode, operands[1], operands[2]);
9710
9711   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
9712   DONE;
9713 })
9714
9715 ;; Convert ashift to the lea pattern to avoid flags dependency.
9716 (define_split
9717   [(set (match_operand:DI 0 "register_operand")
9718         (zero_extend:DI
9719           (ashift:SI (match_operand:SI 1 "index_register_operand")
9720                      (match_operand:QI 2 "const_int_operand"))))
9721    (clobber (reg:CC FLAGS_REG))]
9722   "TARGET_64BIT && reload_completed
9723    && true_regnum (operands[0]) != true_regnum (operands[1])"
9724   [(set (match_dup 0)
9725         (zero_extend:DI (mult:SI (match_dup 1) (match_dup 2))))]
9726 {
9727   operands[1] = gen_lowpart (SImode, operands[1]);
9728   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), SImode);
9729 })
9730
9731 ;; This pattern can't accept a variable shift count, since shifts by
9732 ;; zero don't affect the flags.  We assume that shifts by constant
9733 ;; zero are optimized away.
9734 (define_insn "*ashl<mode>3_cmp"
9735   [(set (reg FLAGS_REG)
9736         (compare
9737           (ashift:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
9738                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
9739           (const_int 0)))
9740    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
9741         (ashift:SWI (match_dup 1) (match_dup 2)))]
9742   "(optimize_function_for_size_p (cfun)
9743     || !TARGET_PARTIAL_FLAG_REG_STALL
9744     || (operands[2] == const1_rtx
9745         && (TARGET_SHIFT1
9746             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
9747    && ix86_match_ccmode (insn, CCGOCmode)
9748    && ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
9749 {
9750   switch (get_attr_type (insn))
9751     {
9752     case TYPE_ALU:
9753       gcc_assert (operands[2] == const1_rtx);
9754       return "add{<imodesuffix>}\t%0, %0";
9755
9756     default:
9757       if (operands[2] == const1_rtx
9758           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9759         return "sal{<imodesuffix>}\t%0";
9760       else
9761         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9762     }
9763 }
9764   [(set (attr "type")
9765      (cond [(and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9766                       (match_operand 0 "register_operand"))
9767                  (match_operand 2 "const1_operand"))
9768               (const_string "alu")
9769            ]
9770            (const_string "ishift")))
9771    (set (attr "length_immediate")
9772      (if_then_else
9773        (ior (eq_attr "type" "alu")
9774             (and (eq_attr "type" "ishift")
9775                  (and (match_operand 2 "const1_operand")
9776                       (ior (match_test "TARGET_SHIFT1")
9777                            (match_test "optimize_function_for_size_p (cfun)")))))
9778        (const_string "0")
9779        (const_string "*")))
9780    (set_attr "mode" "<MODE>")])
9781
9782 (define_insn "*ashlsi3_cmp_zext"
9783   [(set (reg FLAGS_REG)
9784         (compare
9785           (ashift:SI (match_operand:SI 1 "register_operand" "0")
9786                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
9787           (const_int 0)))
9788    (set (match_operand:DI 0 "register_operand" "=r")
9789         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
9790   "TARGET_64BIT
9791    && (optimize_function_for_size_p (cfun)
9792        || !TARGET_PARTIAL_FLAG_REG_STALL
9793        || (operands[2] == const1_rtx
9794            && (TARGET_SHIFT1
9795                || TARGET_DOUBLE_WITH_ADD)))
9796    && ix86_match_ccmode (insn, CCGOCmode)
9797    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
9798 {
9799   switch (get_attr_type (insn))
9800     {
9801     case TYPE_ALU:
9802       gcc_assert (operands[2] == const1_rtx);
9803       return "add{l}\t%k0, %k0";
9804
9805     default:
9806       if (operands[2] == const1_rtx
9807           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9808         return "sal{l}\t%k0";
9809       else
9810         return "sal{l}\t{%2, %k0|%k0, %2}";
9811     }
9812 }
9813   [(set (attr "type")
9814      (cond [(and (match_test "TARGET_DOUBLE_WITH_ADD")
9815                  (match_operand 2 "const1_operand"))
9816               (const_string "alu")
9817            ]
9818            (const_string "ishift")))
9819    (set (attr "length_immediate")
9820      (if_then_else
9821        (ior (eq_attr "type" "alu")
9822             (and (eq_attr "type" "ishift")
9823                  (and (match_operand 2 "const1_operand")
9824                       (ior (match_test "TARGET_SHIFT1")
9825                            (match_test "optimize_function_for_size_p (cfun)")))))
9826        (const_string "0")
9827        (const_string "*")))
9828    (set_attr "mode" "SI")])
9829
9830 (define_insn "*ashl<mode>3_cconly"
9831   [(set (reg FLAGS_REG)
9832         (compare
9833           (ashift:SWI (match_operand:SWI 1 "register_operand" "0")
9834                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
9835           (const_int 0)))
9836    (clobber (match_scratch:SWI 0 "=<r>"))]
9837   "(optimize_function_for_size_p (cfun)
9838     || !TARGET_PARTIAL_FLAG_REG_STALL
9839     || (operands[2] == const1_rtx
9840         && (TARGET_SHIFT1
9841             || TARGET_DOUBLE_WITH_ADD)))
9842    && ix86_match_ccmode (insn, CCGOCmode)"
9843 {
9844   switch (get_attr_type (insn))
9845     {
9846     case TYPE_ALU:
9847       gcc_assert (operands[2] == const1_rtx);
9848       return "add{<imodesuffix>}\t%0, %0";
9849
9850     default:
9851       if (operands[2] == const1_rtx
9852           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9853         return "sal{<imodesuffix>}\t%0";
9854       else
9855         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9856     }
9857 }
9858   [(set (attr "type")
9859      (cond [(and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9860                       (match_operand 0 "register_operand"))
9861                  (match_operand 2 "const1_operand"))
9862               (const_string "alu")
9863            ]
9864            (const_string "ishift")))
9865    (set (attr "length_immediate")
9866      (if_then_else
9867        (ior (eq_attr "type" "alu")
9868             (and (eq_attr "type" "ishift")
9869                  (and (match_operand 2 "const1_operand")
9870                       (ior (match_test "TARGET_SHIFT1")
9871                            (match_test "optimize_function_for_size_p (cfun)")))))
9872        (const_string "0")
9873        (const_string "*")))
9874    (set_attr "mode" "<MODE>")])
9875
9876 ;; See comment above `ashl<mode>3' about how this works.
9877
9878 (define_expand "<shift_insn><mode>3"
9879   [(set (match_operand:SDWIM 0 "<shift_operand>")
9880         (any_shiftrt:SDWIM (match_operand:SDWIM 1 "<shift_operand>")
9881                            (match_operand:QI 2 "nonmemory_operand")))]
9882   ""
9883   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
9884
9885 ;; Avoid useless masking of count operand.
9886 (define_insn "*<shift_insn><mode>3_mask"
9887   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
9888         (any_shiftrt:SWI48
9889           (match_operand:SWI48 1 "nonimmediate_operand" "0")
9890           (subreg:QI
9891             (and:SI
9892               (match_operand:SI 2 "register_operand" "c")
9893               (match_operand:SI 3 "const_int_operand" "n")) 0)))
9894    (clobber (reg:CC FLAGS_REG))]
9895   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
9896    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
9897       == GET_MODE_BITSIZE (<MODE>mode)-1"
9898 {
9899   return "<shift>{<imodesuffix>}\t{%b2, %0|%0, %b2}";
9900 }
9901   [(set_attr "type" "ishift")
9902    (set_attr "mode" "<MODE>")])
9903
9904 (define_insn_and_split "*<shift_insn><mode>3_doubleword"
9905   [(set (match_operand:DWI 0 "register_operand" "=r")
9906         (any_shiftrt:DWI (match_operand:DWI 1 "register_operand" "0")
9907                          (match_operand:QI 2 "nonmemory_operand" "<S>c")))
9908    (clobber (reg:CC FLAGS_REG))]
9909   ""
9910   "#"
9911   "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
9912   [(const_int 0)]
9913   "ix86_split_<shift_insn> (operands, NULL_RTX, <MODE>mode); DONE;"
9914   [(set_attr "type" "multi")])
9915
9916 ;; By default we don't ask for a scratch register, because when DWImode
9917 ;; values are manipulated, registers are already at a premium.  But if
9918 ;; we have one handy, we won't turn it away.
9919
9920 (define_peephole2
9921   [(match_scratch:DWIH 3 "r")
9922    (parallel [(set (match_operand:<DWI> 0 "register_operand")
9923                    (any_shiftrt:<DWI>
9924                      (match_operand:<DWI> 1 "register_operand")
9925                      (match_operand:QI 2 "nonmemory_operand")))
9926               (clobber (reg:CC FLAGS_REG))])
9927    (match_dup 3)]
9928   "TARGET_CMOVE"
9929   [(const_int 0)]
9930   "ix86_split_<shift_insn> (operands, operands[3], <DWI>mode); DONE;")
9931
9932 (define_insn "x86_64_shrd"
9933   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
9934         (ior:DI (lshiftrt:DI (match_dup 0)
9935                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
9936                 (ashift:DI (match_operand:DI 1 "register_operand" "r")
9937                   (minus:QI (const_int 64) (match_dup 2)))))
9938    (clobber (reg:CC FLAGS_REG))]
9939   "TARGET_64BIT"
9940   "shrd{q}\t{%s2%1, %0|%0, %1, %2}"
9941   [(set_attr "type" "ishift")
9942    (set_attr "prefix_0f" "1")
9943    (set_attr "mode" "DI")
9944    (set_attr "athlon_decode" "vector")
9945    (set_attr "amdfam10_decode" "vector")
9946    (set_attr "bdver1_decode" "vector")])
9947
9948 (define_insn "x86_shrd"
9949   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
9950         (ior:SI (lshiftrt:SI (match_dup 0)
9951                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
9952                 (ashift:SI (match_operand:SI 1 "register_operand" "r")
9953                   (minus:QI (const_int 32) (match_dup 2)))))
9954    (clobber (reg:CC FLAGS_REG))]
9955   ""
9956   "shrd{l}\t{%s2%1, %0|%0, %1, %2}"
9957   [(set_attr "type" "ishift")
9958    (set_attr "prefix_0f" "1")
9959    (set_attr "mode" "SI")
9960    (set_attr "pent_pair" "np")
9961    (set_attr "athlon_decode" "vector")
9962    (set_attr "amdfam10_decode" "vector")
9963    (set_attr "bdver1_decode" "vector")])
9964
9965 (define_insn "ashrdi3_cvt"
9966   [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
9967         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
9968                      (match_operand:QI 2 "const_int_operand")))
9969    (clobber (reg:CC FLAGS_REG))]
9970   "TARGET_64BIT && INTVAL (operands[2]) == 63
9971    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9972    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
9973   "@
9974    {cqto|cqo}
9975    sar{q}\t{%2, %0|%0, %2}"
9976   [(set_attr "type" "imovx,ishift")
9977    (set_attr "prefix_0f" "0,*")
9978    (set_attr "length_immediate" "0,*")
9979    (set_attr "modrm" "0,1")
9980    (set_attr "mode" "DI")])
9981
9982 (define_insn "ashrsi3_cvt"
9983   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
9984         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
9985                      (match_operand:QI 2 "const_int_operand")))
9986    (clobber (reg:CC FLAGS_REG))]
9987   "INTVAL (operands[2]) == 31
9988    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9989    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
9990   "@
9991    {cltd|cdq}
9992    sar{l}\t{%2, %0|%0, %2}"
9993   [(set_attr "type" "imovx,ishift")
9994    (set_attr "prefix_0f" "0,*")
9995    (set_attr "length_immediate" "0,*")
9996    (set_attr "modrm" "0,1")
9997    (set_attr "mode" "SI")])
9998
9999 (define_insn "*ashrsi3_cvt_zext"
10000   [(set (match_operand:DI 0 "register_operand" "=*d,r")
10001         (zero_extend:DI
10002           (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
10003                        (match_operand:QI 2 "const_int_operand"))))
10004    (clobber (reg:CC FLAGS_REG))]
10005   "TARGET_64BIT && INTVAL (operands[2]) == 31
10006    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
10007    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
10008   "@
10009    {cltd|cdq}
10010    sar{l}\t{%2, %k0|%k0, %2}"
10011   [(set_attr "type" "imovx,ishift")
10012    (set_attr "prefix_0f" "0,*")
10013    (set_attr "length_immediate" "0,*")
10014    (set_attr "modrm" "0,1")
10015    (set_attr "mode" "SI")])
10016
10017 (define_expand "x86_shift<mode>_adj_3"
10018   [(use (match_operand:SWI48 0 "register_operand"))
10019    (use (match_operand:SWI48 1 "register_operand"))
10020    (use (match_operand:QI 2 "register_operand"))]
10021   ""
10022 {
10023   rtx_code_label *label = gen_label_rtx ();
10024   rtx tmp;
10025
10026   emit_insn (gen_testqi_ccz_1 (operands[2],
10027                                GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
10028
10029   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
10030   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
10031   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
10032                               gen_rtx_LABEL_REF (VOIDmode, label),
10033                               pc_rtx);
10034   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
10035   JUMP_LABEL (tmp) = label;
10036
10037   emit_move_insn (operands[0], operands[1]);
10038   emit_insn (gen_ashr<mode>3_cvt (operands[1], operands[1],
10039                                   GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1)));
10040   emit_label (label);
10041   LABEL_NUSES (label) = 1;
10042
10043   DONE;
10044 })
10045
10046 (define_insn "*bmi2_<shift_insn><mode>3_1"
10047   [(set (match_operand:SWI48 0 "register_operand" "=r")
10048         (any_shiftrt:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm")
10049                            (match_operand:SWI48 2 "register_operand" "r")))]
10050   "TARGET_BMI2"
10051   "<shift>x\t{%2, %1, %0|%0, %1, %2}"
10052   [(set_attr "type" "ishiftx")
10053    (set_attr "mode" "<MODE>")])
10054
10055 (define_insn "*<shift_insn><mode>3_1"
10056   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
10057         (any_shiftrt:SWI48
10058           (match_operand:SWI48 1 "nonimmediate_operand" "0,rm")
10059           (match_operand:QI 2 "nonmemory_operand" "c<S>,r")))
10060    (clobber (reg:CC FLAGS_REG))]
10061   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10062 {
10063   switch (get_attr_type (insn))
10064     {
10065     case TYPE_ISHIFTX:
10066       return "#";
10067
10068     default:
10069       if (operands[2] == const1_rtx
10070           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10071         return "<shift>{<imodesuffix>}\t%0";
10072       else
10073         return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10074     }
10075 }
10076   [(set_attr "isa" "*,bmi2")
10077    (set_attr "type" "ishift,ishiftx")
10078    (set (attr "length_immediate")
10079      (if_then_else
10080        (and (match_operand 2 "const1_operand")
10081             (ior (match_test "TARGET_SHIFT1")
10082                  (match_test "optimize_function_for_size_p (cfun)")))
10083        (const_string "0")
10084        (const_string "*")))
10085    (set_attr "mode" "<MODE>")])
10086
10087 ;; Convert shift to the shiftx pattern to avoid flags dependency.
10088 (define_split
10089   [(set (match_operand:SWI48 0 "register_operand")
10090         (any_shiftrt:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
10091                            (match_operand:QI 2 "register_operand")))
10092    (clobber (reg:CC FLAGS_REG))]
10093   "TARGET_BMI2 && reload_completed"
10094   [(set (match_dup 0)
10095         (any_shiftrt:SWI48 (match_dup 1) (match_dup 2)))]
10096   "operands[2] = gen_lowpart (<MODE>mode, operands[2]);")
10097
10098 (define_insn "*bmi2_<shift_insn>si3_1_zext"
10099   [(set (match_operand:DI 0 "register_operand" "=r")
10100         (zero_extend:DI
10101           (any_shiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "rm")
10102                           (match_operand:SI 2 "register_operand" "r"))))]
10103   "TARGET_64BIT && TARGET_BMI2"
10104   "<shift>x\t{%2, %1, %k0|%k0, %1, %2}"
10105   [(set_attr "type" "ishiftx")
10106    (set_attr "mode" "SI")])
10107
10108 (define_insn "*<shift_insn>si3_1_zext"
10109   [(set (match_operand:DI 0 "register_operand" "=r,r")
10110         (zero_extend:DI
10111           (any_shiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,rm")
10112                           (match_operand:QI 2 "nonmemory_operand" "cI,r"))))
10113    (clobber (reg:CC FLAGS_REG))]
10114   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10115 {
10116   switch (get_attr_type (insn))
10117     {
10118     case TYPE_ISHIFTX:
10119       return "#";
10120
10121     default:
10122       if (operands[2] == const1_rtx
10123           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10124         return "<shift>{l}\t%k0";
10125       else
10126         return "<shift>{l}\t{%2, %k0|%k0, %2}";
10127     }
10128 }
10129   [(set_attr "isa" "*,bmi2")
10130    (set_attr "type" "ishift,ishiftx")
10131    (set (attr "length_immediate")
10132      (if_then_else
10133        (and (match_operand 2 "const1_operand")
10134             (ior (match_test "TARGET_SHIFT1")
10135                  (match_test "optimize_function_for_size_p (cfun)")))
10136        (const_string "0")
10137        (const_string "*")))
10138    (set_attr "mode" "SI")])
10139
10140 ;; Convert shift to the shiftx pattern to avoid flags dependency.
10141 (define_split
10142   [(set (match_operand:DI 0 "register_operand")
10143         (zero_extend:DI
10144           (any_shiftrt:SI (match_operand:SI 1 "nonimmediate_operand")
10145                           (match_operand:QI 2 "register_operand"))))
10146    (clobber (reg:CC FLAGS_REG))]
10147   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
10148   [(set (match_dup 0)
10149         (zero_extend:DI (any_shiftrt:SI (match_dup 1) (match_dup 2))))]
10150   "operands[2] = gen_lowpart (SImode, operands[2]);")
10151
10152 (define_insn "*<shift_insn><mode>3_1"
10153   [(set (match_operand:SWI12 0 "nonimmediate_operand" "=<r>m")
10154         (any_shiftrt:SWI12
10155           (match_operand:SWI12 1 "nonimmediate_operand" "0")
10156           (match_operand:QI 2 "nonmemory_operand" "c<S>")))
10157    (clobber (reg:CC FLAGS_REG))]
10158   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10159 {
10160   if (operands[2] == const1_rtx
10161       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10162     return "<shift>{<imodesuffix>}\t%0";
10163   else
10164     return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10165 }
10166   [(set_attr "type" "ishift")
10167    (set (attr "length_immediate")
10168      (if_then_else
10169        (and (match_operand 2 "const1_operand")
10170             (ior (match_test "TARGET_SHIFT1")
10171                  (match_test "optimize_function_for_size_p (cfun)")))
10172        (const_string "0")
10173        (const_string "*")))
10174    (set_attr "mode" "<MODE>")])
10175
10176 (define_insn "*<shift_insn>qi3_1_slp"
10177   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10178         (any_shiftrt:QI (match_dup 0)
10179                         (match_operand:QI 1 "nonmemory_operand" "cI")))
10180    (clobber (reg:CC FLAGS_REG))]
10181   "(optimize_function_for_size_p (cfun)
10182     || !TARGET_PARTIAL_REG_STALL
10183     || (operands[1] == const1_rtx
10184         && TARGET_SHIFT1))"
10185 {
10186   if (operands[1] == const1_rtx
10187       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10188     return "<shift>{b}\t%0";
10189   else
10190     return "<shift>{b}\t{%1, %0|%0, %1}";
10191 }
10192   [(set_attr "type" "ishift1")
10193    (set (attr "length_immediate")
10194      (if_then_else
10195        (and (match_operand 1 "const1_operand")
10196             (ior (match_test "TARGET_SHIFT1")
10197                  (match_test "optimize_function_for_size_p (cfun)")))
10198        (const_string "0")
10199        (const_string "*")))
10200    (set_attr "mode" "QI")])
10201
10202 ;; This pattern can't accept a variable shift count, since shifts by
10203 ;; zero don't affect the flags.  We assume that shifts by constant
10204 ;; zero are optimized away.
10205 (define_insn "*<shift_insn><mode>3_cmp"
10206   [(set (reg FLAGS_REG)
10207         (compare
10208           (any_shiftrt:SWI
10209             (match_operand:SWI 1 "nonimmediate_operand" "0")
10210             (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
10211           (const_int 0)))
10212    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
10213         (any_shiftrt:SWI (match_dup 1) (match_dup 2)))]
10214   "(optimize_function_for_size_p (cfun)
10215     || !TARGET_PARTIAL_FLAG_REG_STALL
10216     || (operands[2] == const1_rtx
10217         && TARGET_SHIFT1))
10218    && ix86_match_ccmode (insn, CCGOCmode)
10219    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10220 {
10221   if (operands[2] == const1_rtx
10222       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10223     return "<shift>{<imodesuffix>}\t%0";
10224   else
10225     return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10226 }
10227   [(set_attr "type" "ishift")
10228    (set (attr "length_immediate")
10229      (if_then_else
10230        (and (match_operand 2 "const1_operand")
10231             (ior (match_test "TARGET_SHIFT1")
10232                  (match_test "optimize_function_for_size_p (cfun)")))
10233        (const_string "0")
10234        (const_string "*")))
10235    (set_attr "mode" "<MODE>")])
10236
10237 (define_insn "*<shift_insn>si3_cmp_zext"
10238   [(set (reg FLAGS_REG)
10239         (compare
10240           (any_shiftrt:SI (match_operand:SI 1 "register_operand" "0")
10241                           (match_operand:QI 2 "const_1_to_31_operand" "I"))
10242           (const_int 0)))
10243    (set (match_operand:DI 0 "register_operand" "=r")
10244         (zero_extend:DI (any_shiftrt:SI (match_dup 1) (match_dup 2))))]
10245   "TARGET_64BIT
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    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10252 {
10253   if (operands[2] == const1_rtx
10254       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10255     return "<shift>{l}\t%k0";
10256   else
10257     return "<shift>{l}\t{%2, %k0|%k0, %2}";
10258 }
10259   [(set_attr "type" "ishift")
10260    (set (attr "length_immediate")
10261      (if_then_else
10262        (and (match_operand 2 "const1_operand")
10263             (ior (match_test "TARGET_SHIFT1")
10264                  (match_test "optimize_function_for_size_p (cfun)")))
10265        (const_string "0")
10266        (const_string "*")))
10267    (set_attr "mode" "SI")])
10268
10269 (define_insn "*<shift_insn><mode>3_cconly"
10270   [(set (reg FLAGS_REG)
10271         (compare
10272           (any_shiftrt:SWI
10273             (match_operand:SWI 1 "register_operand" "0")
10274             (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
10275           (const_int 0)))
10276    (clobber (match_scratch:SWI 0 "=<r>"))]
10277   "(optimize_function_for_size_p (cfun)
10278     || !TARGET_PARTIAL_FLAG_REG_STALL
10279     || (operands[2] == const1_rtx
10280         && TARGET_SHIFT1))
10281    && ix86_match_ccmode (insn, CCGOCmode)"
10282 {
10283   if (operands[2] == const1_rtx
10284       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10285     return "<shift>{<imodesuffix>}\t%0";
10286   else
10287     return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10288 }
10289   [(set_attr "type" "ishift")
10290    (set (attr "length_immediate")
10291      (if_then_else
10292        (and (match_operand 2 "const1_operand")
10293             (ior (match_test "TARGET_SHIFT1")
10294                  (match_test "optimize_function_for_size_p (cfun)")))
10295        (const_string "0")
10296        (const_string "*")))
10297    (set_attr "mode" "<MODE>")])
10298 \f
10299 ;; Rotate instructions
10300
10301 (define_expand "<rotate_insn>ti3"
10302   [(set (match_operand:TI 0 "register_operand")
10303         (any_rotate:TI (match_operand:TI 1 "register_operand")
10304                        (match_operand:QI 2 "nonmemory_operand")))]
10305   "TARGET_64BIT"
10306 {
10307   if (const_1_to_63_operand (operands[2], VOIDmode))
10308     emit_insn (gen_ix86_<rotate_insn>ti3_doubleword
10309                 (operands[0], operands[1], operands[2]));
10310   else
10311     FAIL;
10312
10313   DONE;
10314 })
10315
10316 (define_expand "<rotate_insn>di3"
10317   [(set (match_operand:DI 0 "shiftdi_operand")
10318         (any_rotate:DI (match_operand:DI 1 "shiftdi_operand")
10319                        (match_operand:QI 2 "nonmemory_operand")))]
10320  ""
10321 {
10322   if (TARGET_64BIT)
10323     ix86_expand_binary_operator (<CODE>, DImode, operands);
10324   else if (const_1_to_31_operand (operands[2], VOIDmode))
10325     emit_insn (gen_ix86_<rotate_insn>di3_doubleword
10326                 (operands[0], operands[1], operands[2]));
10327   else
10328     FAIL;
10329
10330   DONE;
10331 })
10332
10333 (define_expand "<rotate_insn><mode>3"
10334   [(set (match_operand:SWIM124 0 "nonimmediate_operand")
10335         (any_rotate:SWIM124 (match_operand:SWIM124 1 "nonimmediate_operand")
10336                             (match_operand:QI 2 "nonmemory_operand")))]
10337   ""
10338   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
10339
10340 ;; Avoid useless masking of count operand.
10341 (define_insn "*<rotate_insn><mode>3_mask"
10342   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
10343         (any_rotate:SWI48
10344           (match_operand:SWI48 1 "nonimmediate_operand" "0")
10345           (subreg:QI
10346             (and:SI
10347               (match_operand:SI 2 "register_operand" "c")
10348               (match_operand:SI 3 "const_int_operand" "n")) 0)))
10349    (clobber (reg:CC FLAGS_REG))]
10350   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
10351    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
10352       == GET_MODE_BITSIZE (<MODE>mode)-1"
10353 {
10354   return "<rotate>{<imodesuffix>}\t{%b2, %0|%0, %b2}";
10355 }
10356   [(set_attr "type" "rotate")
10357    (set_attr "mode" "<MODE>")])
10358
10359 ;; Implement rotation using two double-precision
10360 ;; shift instructions and a scratch register.
10361
10362 (define_insn_and_split "ix86_rotl<dwi>3_doubleword"
10363  [(set (match_operand:<DWI> 0 "register_operand" "=r")
10364        (rotate:<DWI> (match_operand:<DWI> 1 "register_operand" "0")
10365                      (match_operand:QI 2 "<shift_immediate_operand>" "<S>")))
10366   (clobber (reg:CC FLAGS_REG))
10367   (clobber (match_scratch:DWIH 3 "=&r"))]
10368  ""
10369  "#"
10370  "reload_completed"
10371  [(set (match_dup 3) (match_dup 4))
10372   (parallel
10373    [(set (match_dup 4)
10374          (ior:DWIH (ashift:DWIH (match_dup 4) (match_dup 2))
10375                    (lshiftrt:DWIH (match_dup 5)
10376                                   (minus:QI (match_dup 6) (match_dup 2)))))
10377     (clobber (reg:CC FLAGS_REG))])
10378   (parallel
10379    [(set (match_dup 5)
10380          (ior:DWIH (ashift:DWIH (match_dup 5) (match_dup 2))
10381                    (lshiftrt:DWIH (match_dup 3)
10382                                   (minus:QI (match_dup 6) (match_dup 2)))))
10383     (clobber (reg:CC FLAGS_REG))])]
10384 {
10385   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
10386
10387   split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
10388 })
10389
10390 (define_insn_and_split "ix86_rotr<dwi>3_doubleword"
10391  [(set (match_operand:<DWI> 0 "register_operand" "=r")
10392        (rotatert:<DWI> (match_operand:<DWI> 1 "register_operand" "0")
10393                        (match_operand:QI 2 "<shift_immediate_operand>" "<S>")))
10394   (clobber (reg:CC FLAGS_REG))
10395   (clobber (match_scratch:DWIH 3 "=&r"))]
10396  ""
10397  "#"
10398  "reload_completed"
10399  [(set (match_dup 3) (match_dup 4))
10400   (parallel
10401    [(set (match_dup 4)
10402          (ior:DWIH (lshiftrt:DWIH (match_dup 4) (match_dup 2))
10403                    (ashift:DWIH (match_dup 5)
10404                                 (minus:QI (match_dup 6) (match_dup 2)))))
10405     (clobber (reg:CC FLAGS_REG))])
10406   (parallel
10407    [(set (match_dup 5)
10408          (ior:DWIH (lshiftrt:DWIH (match_dup 5) (match_dup 2))
10409                    (ashift:DWIH (match_dup 3)
10410                                 (minus:QI (match_dup 6) (match_dup 2)))))
10411     (clobber (reg:CC FLAGS_REG))])]
10412 {
10413   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
10414
10415   split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
10416 })
10417
10418 (define_insn "*bmi2_rorx<mode>3_1"
10419   [(set (match_operand:SWI48 0 "register_operand" "=r")
10420         (rotatert:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm")
10421                         (match_operand:QI 2 "immediate_operand" "<S>")))]
10422   "TARGET_BMI2"
10423   "rorx\t{%2, %1, %0|%0, %1, %2}"
10424   [(set_attr "type" "rotatex")
10425    (set_attr "mode" "<MODE>")])
10426
10427 (define_insn "*<rotate_insn><mode>3_1"
10428   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
10429         (any_rotate:SWI48
10430           (match_operand:SWI48 1 "nonimmediate_operand" "0,rm")
10431           (match_operand:QI 2 "nonmemory_operand" "c<S>,<S>")))
10432    (clobber (reg:CC FLAGS_REG))]
10433   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10434 {
10435   switch (get_attr_type (insn))
10436     {
10437     case TYPE_ROTATEX:
10438       return "#";
10439
10440     default:
10441       if (operands[2] == const1_rtx
10442           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10443         return "<rotate>{<imodesuffix>}\t%0";
10444       else
10445         return "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
10446     }
10447 }
10448   [(set_attr "isa" "*,bmi2")
10449    (set_attr "type" "rotate,rotatex")
10450    (set (attr "length_immediate")
10451      (if_then_else
10452        (and (eq_attr "type" "rotate")
10453             (and (match_operand 2 "const1_operand")
10454                  (ior (match_test "TARGET_SHIFT1")
10455                       (match_test "optimize_function_for_size_p (cfun)"))))
10456        (const_string "0")
10457        (const_string "*")))
10458    (set_attr "mode" "<MODE>")])
10459
10460 ;; Convert rotate to the rotatex pattern to avoid flags dependency.
10461 (define_split
10462   [(set (match_operand:SWI48 0 "register_operand")
10463         (rotate:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
10464                       (match_operand:QI 2 "immediate_operand")))
10465    (clobber (reg:CC FLAGS_REG))]
10466   "TARGET_BMI2 && reload_completed"
10467   [(set (match_dup 0)
10468         (rotatert:SWI48 (match_dup 1) (match_dup 2)))]
10469 {
10470   operands[2]
10471     = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - INTVAL (operands[2]));
10472 })
10473
10474 (define_split
10475   [(set (match_operand:SWI48 0 "register_operand")
10476         (rotatert:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
10477                         (match_operand:QI 2 "immediate_operand")))
10478    (clobber (reg:CC FLAGS_REG))]
10479   "TARGET_BMI2 && reload_completed"
10480   [(set (match_dup 0)
10481         (rotatert:SWI48 (match_dup 1) (match_dup 2)))])
10482
10483 (define_insn "*bmi2_rorxsi3_1_zext"
10484   [(set (match_operand:DI 0 "register_operand" "=r")
10485         (zero_extend:DI
10486           (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "rm")
10487                        (match_operand:QI 2 "immediate_operand" "I"))))]
10488   "TARGET_64BIT && TARGET_BMI2"
10489   "rorx\t{%2, %1, %k0|%k0, %1, %2}"
10490   [(set_attr "type" "rotatex")
10491    (set_attr "mode" "SI")])
10492
10493 (define_insn "*<rotate_insn>si3_1_zext"
10494   [(set (match_operand:DI 0 "register_operand" "=r,r")
10495         (zero_extend:DI
10496           (any_rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0,rm")
10497                          (match_operand:QI 2 "nonmemory_operand" "cI,I"))))
10498    (clobber (reg:CC FLAGS_REG))]
10499   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10500 {
10501   switch (get_attr_type (insn))
10502     {
10503     case TYPE_ROTATEX:
10504       return "#";
10505
10506     default:
10507       if (operands[2] == const1_rtx
10508           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10509         return "<rotate>{l}\t%k0";
10510       else
10511         return "<rotate>{l}\t{%2, %k0|%k0, %2}";
10512     }
10513 }
10514   [(set_attr "isa" "*,bmi2")
10515    (set_attr "type" "rotate,rotatex")
10516    (set (attr "length_immediate")
10517      (if_then_else
10518        (and (eq_attr "type" "rotate")
10519             (and (match_operand 2 "const1_operand")
10520                  (ior (match_test "TARGET_SHIFT1")
10521                       (match_test "optimize_function_for_size_p (cfun)"))))
10522        (const_string "0")
10523        (const_string "*")))
10524    (set_attr "mode" "SI")])
10525
10526 ;; Convert rotate to the rotatex pattern to avoid flags dependency.
10527 (define_split
10528   [(set (match_operand:DI 0 "register_operand")
10529         (zero_extend:DI
10530           (rotate:SI (match_operand:SI 1 "nonimmediate_operand")
10531                      (match_operand:QI 2 "immediate_operand"))))
10532    (clobber (reg:CC FLAGS_REG))]
10533   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
10534   [(set (match_dup 0)
10535         (zero_extend:DI (rotatert:SI (match_dup 1) (match_dup 2))))]
10536 {
10537   operands[2]
10538     = GEN_INT (GET_MODE_BITSIZE (SImode) - INTVAL (operands[2]));
10539 })
10540
10541 (define_split
10542   [(set (match_operand:DI 0 "register_operand")
10543         (zero_extend:DI
10544           (rotatert:SI (match_operand:SI 1 "nonimmediate_operand")
10545                        (match_operand:QI 2 "immediate_operand"))))
10546    (clobber (reg:CC FLAGS_REG))]
10547   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
10548   [(set (match_dup 0)
10549         (zero_extend:DI (rotatert:SI (match_dup 1) (match_dup 2))))])
10550
10551 (define_insn "*<rotate_insn><mode>3_1"
10552   [(set (match_operand:SWI12 0 "nonimmediate_operand" "=<r>m")
10553         (any_rotate:SWI12 (match_operand:SWI12 1 "nonimmediate_operand" "0")
10554                           (match_operand:QI 2 "nonmemory_operand" "c<S>")))
10555    (clobber (reg:CC FLAGS_REG))]
10556   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10557 {
10558   if (operands[2] == const1_rtx
10559       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10560     return "<rotate>{<imodesuffix>}\t%0";
10561   else
10562     return "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
10563 }
10564   [(set_attr "type" "rotate")
10565    (set (attr "length_immediate")
10566      (if_then_else
10567        (and (match_operand 2 "const1_operand")
10568             (ior (match_test "TARGET_SHIFT1")
10569                  (match_test "optimize_function_for_size_p (cfun)")))
10570        (const_string "0")
10571        (const_string "*")))
10572    (set_attr "mode" "<MODE>")])
10573
10574 (define_insn "*<rotate_insn>qi3_1_slp"
10575   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10576         (any_rotate:QI (match_dup 0)
10577                        (match_operand:QI 1 "nonmemory_operand" "cI")))
10578    (clobber (reg:CC FLAGS_REG))]
10579   "(optimize_function_for_size_p (cfun)
10580     || !TARGET_PARTIAL_REG_STALL
10581     || (operands[1] == const1_rtx
10582         && TARGET_SHIFT1))"
10583 {
10584   if (operands[1] == const1_rtx
10585       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10586     return "<rotate>{b}\t%0";
10587   else
10588     return "<rotate>{b}\t{%1, %0|%0, %1}";
10589 }
10590   [(set_attr "type" "rotate1")
10591    (set (attr "length_immediate")
10592      (if_then_else
10593        (and (match_operand 1 "const1_operand")
10594             (ior (match_test "TARGET_SHIFT1")
10595                  (match_test "optimize_function_for_size_p (cfun)")))
10596        (const_string "0")
10597        (const_string "*")))
10598    (set_attr "mode" "QI")])
10599
10600 (define_split
10601  [(set (match_operand:HI 0 "register_operand")
10602        (any_rotate:HI (match_dup 0) (const_int 8)))
10603   (clobber (reg:CC FLAGS_REG))]
10604  "reload_completed
10605   && (TARGET_USE_XCHGB || optimize_function_for_size_p (cfun))"
10606  [(parallel [(set (strict_low_part (match_dup 0))
10607                   (bswap:HI (match_dup 0)))
10608              (clobber (reg:CC FLAGS_REG))])])
10609 \f
10610 ;; Bit set / bit test instructions
10611
10612 (define_expand "extv"
10613   [(set (match_operand:SI 0 "register_operand")
10614         (sign_extract:SI (match_operand:SI 1 "register_operand")
10615                          (match_operand:SI 2 "const8_operand")
10616                          (match_operand:SI 3 "const8_operand")))]
10617   ""
10618 {
10619   /* Handle extractions from %ah et al.  */
10620   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
10621     FAIL;
10622
10623   /* From mips.md: extract_bit_field doesn't verify that our source
10624      matches the predicate, so check it again here.  */
10625   if (! ext_register_operand (operands[1], VOIDmode))
10626     FAIL;
10627 })
10628
10629 (define_expand "extzv"
10630   [(set (match_operand:SI 0 "register_operand")
10631         (zero_extract:SI (match_operand 1 "ext_register_operand")
10632                          (match_operand:SI 2 "const8_operand")
10633                          (match_operand:SI 3 "const8_operand")))]
10634   ""
10635 {
10636   /* Handle extractions from %ah et al.  */
10637   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
10638     FAIL;
10639
10640   /* From mips.md: extract_bit_field doesn't verify that our source
10641      matches the predicate, so check it again here.  */
10642   if (! ext_register_operand (operands[1], VOIDmode))
10643     FAIL;
10644 })
10645
10646 (define_expand "insv"
10647   [(set (zero_extract (match_operand 0 "register_operand")
10648                       (match_operand 1 "const_int_operand")
10649                       (match_operand 2 "const_int_operand"))
10650         (match_operand 3 "register_operand"))]
10651   ""
10652 {
10653   rtx (*gen_mov_insv_1) (rtx, rtx);
10654
10655   if (ix86_expand_pinsr (operands))
10656     DONE;
10657
10658   /* Handle insertions to %ah et al.  */
10659   if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) != 8)
10660     FAIL;
10661
10662   /* From mips.md: insert_bit_field doesn't verify that our source
10663      matches the predicate, so check it again here.  */
10664   if (! ext_register_operand (operands[0], VOIDmode))
10665     FAIL;
10666
10667   gen_mov_insv_1 = (TARGET_64BIT
10668                     ? gen_movdi_insv_1 : gen_movsi_insv_1);
10669
10670   emit_insn (gen_mov_insv_1 (operands[0], operands[3]));
10671   DONE;
10672 })
10673
10674 ;; %%% bts, btr, btc, bt.
10675 ;; In general these instructions are *slow* when applied to memory,
10676 ;; since they enforce atomic operation.  When applied to registers,
10677 ;; it depends on the cpu implementation.  They're never faster than
10678 ;; the corresponding and/ior/xor operations, so with 32-bit there's
10679 ;; no point.  But in 64-bit, we can't hold the relevant immediates
10680 ;; within the instruction itself, so operating on bits in the high
10681 ;; 32-bits of a register becomes easier.
10682 ;;
10683 ;; These are slow on Nocona, but fast on Athlon64.  We do require the use
10684 ;; of btrq and btcq for corner cases of post-reload expansion of absdf and
10685 ;; negdf respectively, so they can never be disabled entirely.
10686
10687 (define_insn "*btsq"
10688   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10689                          (const_int 1)
10690                          (match_operand:DI 1 "const_0_to_63_operand"))
10691         (const_int 1))
10692    (clobber (reg:CC FLAGS_REG))]
10693   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10694   "bts{q}\t{%1, %0|%0, %1}"
10695   [(set_attr "type" "alu1")
10696    (set_attr "prefix_0f" "1")
10697    (set_attr "mode" "DI")])
10698
10699 (define_insn "*btrq"
10700   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10701                          (const_int 1)
10702                          (match_operand:DI 1 "const_0_to_63_operand"))
10703         (const_int 0))
10704    (clobber (reg:CC FLAGS_REG))]
10705   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10706   "btr{q}\t{%1, %0|%0, %1}"
10707   [(set_attr "type" "alu1")
10708    (set_attr "prefix_0f" "1")
10709    (set_attr "mode" "DI")])
10710
10711 (define_insn "*btcq"
10712   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10713                          (const_int 1)
10714                          (match_operand:DI 1 "const_0_to_63_operand"))
10715         (not:DI (zero_extract:DI (match_dup 0) (const_int 1) (match_dup 1))))
10716    (clobber (reg:CC FLAGS_REG))]
10717   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10718   "btc{q}\t{%1, %0|%0, %1}"
10719   [(set_attr "type" "alu1")
10720    (set_attr "prefix_0f" "1")
10721    (set_attr "mode" "DI")])
10722
10723 ;; Allow Nocona to avoid these instructions if a register is available.
10724
10725 (define_peephole2
10726   [(match_scratch:DI 2 "r")
10727    (parallel [(set (zero_extract:DI
10728                      (match_operand:DI 0 "register_operand")
10729                      (const_int 1)
10730                      (match_operand:DI 1 "const_0_to_63_operand"))
10731                    (const_int 1))
10732               (clobber (reg:CC FLAGS_REG))])]
10733   "TARGET_64BIT && !TARGET_USE_BT"
10734   [(const_int 0)]
10735 {
10736   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10737   rtx op1;
10738
10739   if (HOST_BITS_PER_WIDE_INT >= 64)
10740     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10741   else if (i < HOST_BITS_PER_WIDE_INT)
10742     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10743   else
10744     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10745
10746   op1 = immed_double_const (lo, hi, DImode);
10747   if (i >= 31)
10748     {
10749       emit_move_insn (operands[2], op1);
10750       op1 = operands[2];
10751     }
10752
10753   emit_insn (gen_iordi3 (operands[0], operands[0], op1));
10754   DONE;
10755 })
10756
10757 (define_peephole2
10758   [(match_scratch:DI 2 "r")
10759    (parallel [(set (zero_extract:DI
10760                      (match_operand:DI 0 "register_operand")
10761                      (const_int 1)
10762                      (match_operand:DI 1 "const_0_to_63_operand"))
10763                    (const_int 0))
10764               (clobber (reg:CC FLAGS_REG))])]
10765   "TARGET_64BIT && !TARGET_USE_BT"
10766   [(const_int 0)]
10767 {
10768   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10769   rtx op1;
10770
10771   if (HOST_BITS_PER_WIDE_INT >= 64)
10772     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10773   else if (i < HOST_BITS_PER_WIDE_INT)
10774     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10775   else
10776     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10777
10778   op1 = immed_double_const (~lo, ~hi, DImode);
10779   if (i >= 32)
10780     {
10781       emit_move_insn (operands[2], op1);
10782       op1 = operands[2];
10783     }
10784
10785   emit_insn (gen_anddi3 (operands[0], operands[0], op1));
10786   DONE;
10787 })
10788
10789 (define_peephole2
10790   [(match_scratch:DI 2 "r")
10791    (parallel [(set (zero_extract:DI
10792                      (match_operand:DI 0 "register_operand")
10793                      (const_int 1)
10794                      (match_operand:DI 1 "const_0_to_63_operand"))
10795               (not:DI (zero_extract:DI
10796                         (match_dup 0) (const_int 1) (match_dup 1))))
10797               (clobber (reg:CC FLAGS_REG))])]
10798   "TARGET_64BIT && !TARGET_USE_BT"
10799   [(const_int 0)]
10800 {
10801   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10802   rtx op1;
10803
10804   if (HOST_BITS_PER_WIDE_INT >= 64)
10805     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10806   else if (i < HOST_BITS_PER_WIDE_INT)
10807     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10808   else
10809     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10810
10811   op1 = immed_double_const (lo, hi, DImode);
10812   if (i >= 31)
10813     {
10814       emit_move_insn (operands[2], op1);
10815       op1 = operands[2];
10816     }
10817
10818   emit_insn (gen_xordi3 (operands[0], operands[0], op1));
10819   DONE;
10820 })
10821
10822 (define_insn "*bt<mode>"
10823   [(set (reg:CCC FLAGS_REG)
10824         (compare:CCC
10825           (zero_extract:SWI48
10826             (match_operand:SWI48 0 "register_operand" "r")
10827             (const_int 1)
10828             (match_operand:SWI48 1 "x86_64_nonmemory_operand" "rN"))
10829           (const_int 0)))]
10830   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
10831   "bt{<imodesuffix>}\t{%1, %0|%0, %1}"
10832   [(set_attr "type" "alu1")
10833    (set_attr "prefix_0f" "1")
10834    (set_attr "mode" "<MODE>")])
10835 \f
10836 ;; Store-flag instructions.
10837
10838 ;; For all sCOND expanders, also expand the compare or test insn that
10839 ;; generates cc0.  Generate an equality comparison if `seq' or `sne'.
10840
10841 (define_insn_and_split "*setcc_di_1"
10842   [(set (match_operand:DI 0 "register_operand" "=q")
10843         (match_operator:DI 1 "ix86_comparison_operator"
10844           [(reg FLAGS_REG) (const_int 0)]))]
10845   "TARGET_64BIT && !TARGET_PARTIAL_REG_STALL"
10846   "#"
10847   "&& reload_completed"
10848   [(set (match_dup 2) (match_dup 1))
10849    (set (match_dup 0) (zero_extend:DI (match_dup 2)))]
10850 {
10851   operands[1] = shallow_copy_rtx (operands[1]);
10852   PUT_MODE (operands[1], QImode);
10853   operands[2] = gen_lowpart (QImode, operands[0]);
10854 })
10855
10856 (define_insn_and_split "*setcc_si_1_and"
10857   [(set (match_operand:SI 0 "register_operand" "=q")
10858         (match_operator:SI 1 "ix86_comparison_operator"
10859           [(reg FLAGS_REG) (const_int 0)]))
10860    (clobber (reg:CC FLAGS_REG))]
10861   "!TARGET_PARTIAL_REG_STALL
10862    && TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
10863   "#"
10864   "&& reload_completed"
10865   [(set (match_dup 2) (match_dup 1))
10866    (parallel [(set (match_dup 0) (zero_extend:SI (match_dup 2)))
10867               (clobber (reg:CC FLAGS_REG))])]
10868 {
10869   operands[1] = shallow_copy_rtx (operands[1]);
10870   PUT_MODE (operands[1], QImode);
10871   operands[2] = gen_lowpart (QImode, operands[0]);
10872 })
10873
10874 (define_insn_and_split "*setcc_si_1_movzbl"
10875   [(set (match_operand:SI 0 "register_operand" "=q")
10876         (match_operator:SI 1 "ix86_comparison_operator"
10877           [(reg FLAGS_REG) (const_int 0)]))]
10878   "!TARGET_PARTIAL_REG_STALL
10879    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))"
10880   "#"
10881   "&& reload_completed"
10882   [(set (match_dup 2) (match_dup 1))
10883    (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
10884 {
10885   operands[1] = shallow_copy_rtx (operands[1]);
10886   PUT_MODE (operands[1], QImode);
10887   operands[2] = gen_lowpart (QImode, operands[0]);
10888 })
10889
10890 (define_insn "*setcc_qi"
10891   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10892         (match_operator:QI 1 "ix86_comparison_operator"
10893           [(reg FLAGS_REG) (const_int 0)]))]
10894   ""
10895   "set%C1\t%0"
10896   [(set_attr "type" "setcc")
10897    (set_attr "mode" "QI")])
10898
10899 (define_insn "*setcc_qi_slp"
10900   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10901         (match_operator:QI 1 "ix86_comparison_operator"
10902           [(reg FLAGS_REG) (const_int 0)]))]
10903   ""
10904   "set%C1\t%0"
10905   [(set_attr "type" "setcc")
10906    (set_attr "mode" "QI")])
10907
10908 ;; In general it is not safe to assume too much about CCmode registers,
10909 ;; so simplify-rtx stops when it sees a second one.  Under certain
10910 ;; conditions this is safe on x86, so help combine not create
10911 ;;
10912 ;;      seta    %al
10913 ;;      testb   %al, %al
10914 ;;      sete    %al
10915
10916 (define_split
10917   [(set (match_operand:QI 0 "nonimmediate_operand")
10918         (ne:QI (match_operator 1 "ix86_comparison_operator"
10919                  [(reg FLAGS_REG) (const_int 0)])
10920             (const_int 0)))]
10921   ""
10922   [(set (match_dup 0) (match_dup 1))]
10923 {
10924   operands[1] = shallow_copy_rtx (operands[1]);
10925   PUT_MODE (operands[1], QImode);
10926 })
10927
10928 (define_split
10929   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand"))
10930         (ne:QI (match_operator 1 "ix86_comparison_operator"
10931                  [(reg FLAGS_REG) (const_int 0)])
10932             (const_int 0)))]
10933   ""
10934   [(set (match_dup 0) (match_dup 1))]
10935 {
10936   operands[1] = shallow_copy_rtx (operands[1]);
10937   PUT_MODE (operands[1], QImode);
10938 })
10939
10940 (define_split
10941   [(set (match_operand:QI 0 "nonimmediate_operand")
10942         (eq:QI (match_operator 1 "ix86_comparison_operator"
10943                  [(reg FLAGS_REG) (const_int 0)])
10944             (const_int 0)))]
10945   ""
10946   [(set (match_dup 0) (match_dup 1))]
10947 {
10948   operands[1] = shallow_copy_rtx (operands[1]);
10949   PUT_MODE (operands[1], QImode);
10950   PUT_CODE (operands[1],
10951             ix86_reverse_condition (GET_CODE (operands[1]),
10952                                     GET_MODE (XEXP (operands[1], 0))));
10953
10954   /* Make sure that (a) the CCmode we have for the flags is strong
10955      enough for the reversed compare or (b) we have a valid FP compare.  */
10956   if (! ix86_comparison_operator (operands[1], VOIDmode))
10957     FAIL;
10958 })
10959
10960 (define_split
10961   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand"))
10962         (eq:QI (match_operator 1 "ix86_comparison_operator"
10963                  [(reg FLAGS_REG) (const_int 0)])
10964             (const_int 0)))]
10965   ""
10966   [(set (match_dup 0) (match_dup 1))]
10967 {
10968   operands[1] = shallow_copy_rtx (operands[1]);
10969   PUT_MODE (operands[1], QImode);
10970   PUT_CODE (operands[1],
10971             ix86_reverse_condition (GET_CODE (operands[1]),
10972                                     GET_MODE (XEXP (operands[1], 0))));
10973
10974   /* Make sure that (a) the CCmode we have for the flags is strong
10975      enough for the reversed compare or (b) we have a valid FP compare.  */
10976   if (! ix86_comparison_operator (operands[1], VOIDmode))
10977     FAIL;
10978 })
10979
10980 ;; The SSE store flag instructions saves 0 or 0xffffffff to the result.
10981 ;; subsequent logical operations are used to imitate conditional moves.
10982 ;; 0xffffffff is NaN, but not in normalized form, so we can't represent
10983 ;; it directly.
10984
10985 (define_insn "setcc_<mode>_sse"
10986   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
10987         (match_operator:MODEF 3 "sse_comparison_operator"
10988           [(match_operand:MODEF 1 "register_operand" "0,x")
10989            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]))]
10990   "SSE_FLOAT_MODE_P (<MODE>mode)"
10991   "@
10992    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
10993    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10994   [(set_attr "isa" "noavx,avx")
10995    (set_attr "type" "ssecmp")
10996    (set_attr "length_immediate" "1")
10997    (set_attr "prefix" "orig,vex")
10998    (set_attr "mode" "<MODE>")])
10999 \f
11000 ;; Basic conditional jump instructions.
11001 ;; We ignore the overflow flag for signed branch instructions.
11002
11003 (define_insn "*jcc_1_bnd"
11004   [(set (pc)
11005         (if_then_else (match_operator 1 "ix86_comparison_operator"
11006                                       [(reg FLAGS_REG) (const_int 0)])
11007                       (label_ref (match_operand 0))
11008                       (pc)))]
11009   "TARGET_MPX && ix86_bnd_prefixed_insn_p (insn)"
11010   "bnd %+j%C1\t%l0"
11011   [(set_attr "type" "ibr")
11012    (set_attr "modrm" "0")
11013    (set (attr "length")
11014            (if_then_else (and (ge (minus (match_dup 0) (pc))
11015                                   (const_int -126))
11016                               (lt (minus (match_dup 0) (pc))
11017                                   (const_int 128)))
11018              (const_int 3)
11019              (const_int 7)))])
11020
11021 (define_insn "*jcc_1"
11022   [(set (pc)
11023         (if_then_else (match_operator 1 "ix86_comparison_operator"
11024                                       [(reg FLAGS_REG) (const_int 0)])
11025                       (label_ref (match_operand 0))
11026                       (pc)))]
11027   ""
11028   "%+j%C1\t%l0"
11029   [(set_attr "type" "ibr")
11030    (set_attr "modrm" "0")
11031    (set (attr "length")
11032            (if_then_else (and (ge (minus (match_dup 0) (pc))
11033                                   (const_int -126))
11034                               (lt (minus (match_dup 0) (pc))
11035                                   (const_int 128)))
11036              (const_int 2)
11037              (const_int 6)))])
11038
11039 (define_insn "*jcc_2_bnd"
11040   [(set (pc)
11041         (if_then_else (match_operator 1 "ix86_comparison_operator"
11042                                       [(reg FLAGS_REG) (const_int 0)])
11043                       (pc)
11044                       (label_ref (match_operand 0))))]
11045   "TARGET_MPX && ix86_bnd_prefixed_insn_p (insn)"
11046   "bnd %+j%c1\t%l0"
11047   [(set_attr "type" "ibr")
11048    (set_attr "modrm" "0")
11049    (set (attr "length")
11050            (if_then_else (and (ge (minus (match_dup 0) (pc))
11051                                   (const_int -126))
11052                               (lt (minus (match_dup 0) (pc))
11053                                   (const_int 128)))
11054              (const_int 3)
11055              (const_int 7)))])
11056
11057 (define_insn "*jcc_2"
11058   [(set (pc)
11059         (if_then_else (match_operator 1 "ix86_comparison_operator"
11060                                       [(reg FLAGS_REG) (const_int 0)])
11061                       (pc)
11062                       (label_ref (match_operand 0))))]
11063   ""
11064   "%+j%c1\t%l0"
11065   [(set_attr "type" "ibr")
11066    (set_attr "modrm" "0")
11067    (set (attr "length")
11068            (if_then_else (and (ge (minus (match_dup 0) (pc))
11069                                   (const_int -126))
11070                               (lt (minus (match_dup 0) (pc))
11071                                   (const_int 128)))
11072              (const_int 2)
11073              (const_int 6)))])
11074
11075 ;; In general it is not safe to assume too much about CCmode registers,
11076 ;; so simplify-rtx stops when it sees a second one.  Under certain
11077 ;; conditions this is safe on x86, so help combine not create
11078 ;;
11079 ;;      seta    %al
11080 ;;      testb   %al, %al
11081 ;;      je      Lfoo
11082
11083 (define_split
11084   [(set (pc)
11085         (if_then_else (ne (match_operator 0 "ix86_comparison_operator"
11086                                       [(reg FLAGS_REG) (const_int 0)])
11087                           (const_int 0))
11088                       (label_ref (match_operand 1))
11089                       (pc)))]
11090   ""
11091   [(set (pc)
11092         (if_then_else (match_dup 0)
11093                       (label_ref (match_dup 1))
11094                       (pc)))]
11095 {
11096   operands[0] = shallow_copy_rtx (operands[0]);
11097   PUT_MODE (operands[0], VOIDmode);
11098 })
11099
11100 (define_split
11101   [(set (pc)
11102         (if_then_else (eq (match_operator 0 "ix86_comparison_operator"
11103                                       [(reg FLAGS_REG) (const_int 0)])
11104                           (const_int 0))
11105                       (label_ref (match_operand 1))
11106                       (pc)))]
11107   ""
11108   [(set (pc)
11109         (if_then_else (match_dup 0)
11110                       (label_ref (match_dup 1))
11111                       (pc)))]
11112 {
11113   operands[0] = shallow_copy_rtx (operands[0]);
11114   PUT_MODE (operands[0], VOIDmode);
11115   PUT_CODE (operands[0],
11116             ix86_reverse_condition (GET_CODE (operands[0]),
11117                                     GET_MODE (XEXP (operands[0], 0))));
11118
11119   /* Make sure that (a) the CCmode we have for the flags is strong
11120      enough for the reversed compare or (b) we have a valid FP compare.  */
11121   if (! ix86_comparison_operator (operands[0], VOIDmode))
11122     FAIL;
11123 })
11124
11125 ;; zero_extend in SImode is correct also for DImode, since this is what combine
11126 ;; pass generates from shift insn with QImode operand.  Actually, the mode
11127 ;; of operand 2 (bit offset operand) doesn't matter since bt insn takes
11128 ;; appropriate modulo of the bit offset value.
11129
11130 (define_insn_and_split "*jcc_bt<mode>"
11131   [(set (pc)
11132         (if_then_else (match_operator 0 "bt_comparison_operator"
11133                         [(zero_extract:SWI48
11134                            (match_operand:SWI48 1 "register_operand" "r")
11135                            (const_int 1)
11136                            (zero_extend:SI
11137                              (match_operand:QI 2 "register_operand" "r")))
11138                          (const_int 0)])
11139                       (label_ref (match_operand 3))
11140                       (pc)))
11141    (clobber (reg:CC FLAGS_REG))]
11142   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
11143   "#"
11144   "&& 1"
11145   [(set (reg:CCC FLAGS_REG)
11146         (compare:CCC
11147           (zero_extract:SWI48
11148             (match_dup 1)
11149             (const_int 1)
11150             (match_dup 2))
11151           (const_int 0)))
11152    (set (pc)
11153         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11154                       (label_ref (match_dup 3))
11155                       (pc)))]
11156 {
11157   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], QImode, 0);
11158   operands[0] = shallow_copy_rtx (operands[0]);
11159   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11160 })
11161
11162 ;; Like *jcc_bt<mode>, but expect a SImode operand 2 instead of QImode
11163 ;; zero extended to SImode.
11164 (define_insn_and_split "*jcc_bt<mode>_1"
11165   [(set (pc)
11166         (if_then_else (match_operator 0 "bt_comparison_operator"
11167                         [(zero_extract:SWI48
11168                            (match_operand:SWI48 1 "register_operand" "r")
11169                            (const_int 1)
11170                            (match_operand:SI 2 "register_operand" "r"))
11171                          (const_int 0)])
11172                       (label_ref (match_operand 3))
11173                       (pc)))
11174    (clobber (reg:CC FLAGS_REG))]
11175   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
11176   "#"
11177   "&& 1"
11178   [(set (reg:CCC FLAGS_REG)
11179         (compare:CCC
11180           (zero_extract:SWI48
11181             (match_dup 1)
11182             (const_int 1)
11183             (match_dup 2))
11184           (const_int 0)))
11185    (set (pc)
11186         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11187                       (label_ref (match_dup 3))
11188                       (pc)))]
11189 {
11190   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], SImode, 0);
11191   operands[0] = shallow_copy_rtx (operands[0]);
11192   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11193 })
11194
11195 ;; Avoid useless masking of bit offset operand.  "and" in SImode is correct
11196 ;; also for DImode, this is what combine produces.
11197 (define_insn_and_split "*jcc_bt<mode>_mask"
11198   [(set (pc)
11199         (if_then_else (match_operator 0 "bt_comparison_operator"
11200                         [(zero_extract:SWI48
11201                            (match_operand:SWI48 1 "register_operand" "r")
11202                            (const_int 1)
11203                            (and:SI
11204                              (match_operand:SI 2 "register_operand" "r")
11205                              (match_operand:SI 3 "const_int_operand" "n")))])
11206                       (label_ref (match_operand 4))
11207                       (pc)))
11208    (clobber (reg:CC FLAGS_REG))]
11209   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
11210    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
11211       == GET_MODE_BITSIZE (<MODE>mode)-1"
11212   "#"
11213   "&& 1"
11214   [(set (reg:CCC FLAGS_REG)
11215         (compare:CCC
11216           (zero_extract:SWI48
11217             (match_dup 1)
11218             (const_int 1)
11219             (match_dup 2))
11220           (const_int 0)))
11221    (set (pc)
11222         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11223                       (label_ref (match_dup 4))
11224                       (pc)))]
11225 {
11226   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], SImode, 0);
11227   operands[0] = shallow_copy_rtx (operands[0]);
11228   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11229 })
11230
11231 (define_insn_and_split "*jcc_btsi_1"
11232   [(set (pc)
11233         (if_then_else (match_operator 0 "bt_comparison_operator"
11234                         [(and:SI
11235                            (lshiftrt:SI
11236                              (match_operand:SI 1 "register_operand" "r")
11237                              (match_operand:QI 2 "register_operand" "r"))
11238                            (const_int 1))
11239                          (const_int 0)])
11240                       (label_ref (match_operand 3))
11241                       (pc)))
11242    (clobber (reg:CC FLAGS_REG))]
11243   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
11244   "#"
11245   "&& 1"
11246   [(set (reg:CCC FLAGS_REG)
11247         (compare:CCC
11248           (zero_extract:SI
11249             (match_dup 1)
11250             (const_int 1)
11251             (match_dup 2))
11252           (const_int 0)))
11253    (set (pc)
11254         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11255                       (label_ref (match_dup 3))
11256                       (pc)))]
11257 {
11258   operands[2] = simplify_gen_subreg (SImode, operands[2], QImode, 0);
11259   operands[0] = shallow_copy_rtx (operands[0]);
11260   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11261 })
11262
11263 ;; avoid useless masking of bit offset operand
11264 (define_insn_and_split "*jcc_btsi_mask_1"
11265   [(set (pc)
11266         (if_then_else
11267           (match_operator 0 "bt_comparison_operator"
11268             [(and:SI
11269                (lshiftrt:SI
11270                  (match_operand:SI 1 "register_operand" "r")
11271                  (subreg:QI
11272                    (and:SI
11273                      (match_operand:SI 2 "register_operand" "r")
11274                      (match_operand:SI 3 "const_int_operand" "n")) 0))
11275                (const_int 1))
11276              (const_int 0)])
11277           (label_ref (match_operand 4))
11278           (pc)))
11279    (clobber (reg:CC FLAGS_REG))]
11280   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
11281    && (INTVAL (operands[3]) & 0x1f) == 0x1f"
11282   "#"
11283   "&& 1"
11284   [(set (reg:CCC FLAGS_REG)
11285         (compare:CCC
11286           (zero_extract:SI
11287             (match_dup 1)
11288             (const_int 1)
11289             (match_dup 2))
11290           (const_int 0)))
11291    (set (pc)
11292         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11293                       (label_ref (match_dup 4))
11294                       (pc)))]
11295 {
11296   operands[0] = shallow_copy_rtx (operands[0]);
11297   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11298 })
11299
11300 ;; Define combination compare-and-branch fp compare instructions to help
11301 ;; combine.
11302
11303 (define_insn "*jcc<mode>_0_i387"
11304   [(set (pc)
11305         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11306                         [(match_operand:X87MODEF 1 "register_operand" "f")
11307                          (match_operand:X87MODEF 2 "const0_operand")])
11308           (label_ref (match_operand 3))
11309           (pc)))
11310    (clobber (reg:CCFP FPSR_REG))
11311    (clobber (reg:CCFP FLAGS_REG))
11312    (clobber (match_scratch:HI 4 "=a"))]
11313   "TARGET_80387 && !TARGET_CMOVE"
11314   "#")
11315
11316 (define_insn "*jcc<mode>_0_r_i387"
11317   [(set (pc)
11318         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11319                         [(match_operand:X87MODEF 1 "register_operand" "f")
11320                          (match_operand:X87MODEF 2 "const0_operand")])
11321           (pc)
11322           (label_ref (match_operand 3))))
11323    (clobber (reg:CCFP FPSR_REG))
11324    (clobber (reg:CCFP FLAGS_REG))
11325    (clobber (match_scratch:HI 4 "=a"))]
11326   "TARGET_80387 && !TARGET_CMOVE"
11327   "#")
11328
11329 (define_insn "*jccxf_i387"
11330   [(set (pc)
11331         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11332                         [(match_operand:XF 1 "register_operand" "f")
11333                          (match_operand:XF 2 "register_operand" "f")])
11334           (label_ref (match_operand 3))
11335           (pc)))
11336    (clobber (reg:CCFP FPSR_REG))
11337    (clobber (reg:CCFP FLAGS_REG))
11338    (clobber (match_scratch:HI 4 "=a"))]
11339   "TARGET_80387 && !TARGET_CMOVE"
11340   "#")
11341
11342 (define_insn "*jccxf_r_i387"
11343   [(set (pc)
11344         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11345                         [(match_operand:XF 1 "register_operand" "f")
11346                          (match_operand:XF 2 "register_operand" "f")])
11347           (pc)
11348           (label_ref (match_operand 3))))
11349    (clobber (reg:CCFP FPSR_REG))
11350    (clobber (reg:CCFP FLAGS_REG))
11351    (clobber (match_scratch:HI 4 "=a"))]
11352   "TARGET_80387 && !TARGET_CMOVE"
11353   "#")
11354
11355 (define_insn "*jcc<mode>_i387"
11356   [(set (pc)
11357         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11358                         [(match_operand:MODEF 1 "register_operand" "f")
11359                          (match_operand:MODEF 2 "nonimmediate_operand" "fm")])
11360           (label_ref (match_operand 3))
11361           (pc)))
11362    (clobber (reg:CCFP FPSR_REG))
11363    (clobber (reg:CCFP FLAGS_REG))
11364    (clobber (match_scratch:HI 4 "=a"))]
11365   "TARGET_80387 && !TARGET_CMOVE"
11366   "#")
11367
11368 (define_insn "*jcc<mode>_r_i387"
11369   [(set (pc)
11370         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11371                         [(match_operand:MODEF 1 "register_operand" "f")
11372                          (match_operand:MODEF 2 "nonimmediate_operand" "fm")])
11373           (pc)
11374           (label_ref (match_operand 3))))
11375    (clobber (reg:CCFP FPSR_REG))
11376    (clobber (reg:CCFP FLAGS_REG))
11377    (clobber (match_scratch:HI 4 "=a"))]
11378   "TARGET_80387 && !TARGET_CMOVE"
11379   "#")
11380
11381 (define_insn "*jccu<mode>_i387"
11382   [(set (pc)
11383         (if_then_else (match_operator:CCFPU 0 "ix86_fp_comparison_operator"
11384                         [(match_operand:X87MODEF 1 "register_operand" "f")
11385                          (match_operand:X87MODEF 2 "register_operand" "f")])
11386           (label_ref (match_operand 3))
11387           (pc)))
11388    (clobber (reg:CCFP FPSR_REG))
11389    (clobber (reg:CCFP FLAGS_REG))
11390    (clobber (match_scratch:HI 4 "=a"))]
11391   "TARGET_80387 && !TARGET_CMOVE"
11392   "#")
11393
11394 (define_insn "*jccu<mode>_r_i387"
11395   [(set (pc)
11396         (if_then_else (match_operator:CCFPU 0 "ix86_fp_comparison_operator"
11397                         [(match_operand:X87MODEF 1 "register_operand" "f")
11398                          (match_operand:X87MODEF 2 "register_operand" "f")])
11399           (pc)
11400           (label_ref (match_operand 3))))
11401    (clobber (reg:CCFP FPSR_REG))
11402    (clobber (reg:CCFP FLAGS_REG))
11403    (clobber (match_scratch:HI 4 "=a"))]
11404   "TARGET_80387 && !TARGET_CMOVE"
11405   "#")
11406
11407 (define_split
11408   [(set (pc)
11409         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11410                         [(match_operand:X87MODEF 1 "register_operand")
11411                          (match_operand:X87MODEF 2 "nonimmediate_operand")])
11412           (match_operand 3)
11413           (match_operand 4)))
11414    (clobber (reg:CCFP FPSR_REG))
11415    (clobber (reg:CCFP FLAGS_REG))]
11416   "TARGET_80387 && !TARGET_CMOVE
11417    && reload_completed"
11418   [(const_int 0)]
11419 {
11420   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
11421                         operands[3], operands[4], NULL_RTX);
11422   DONE;
11423 })
11424
11425 (define_split
11426   [(set (pc)
11427         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11428                         [(match_operand:X87MODEF 1 "register_operand")
11429                          (match_operand:X87MODEF 2 "general_operand")])
11430           (match_operand 3)
11431           (match_operand 4)))
11432    (clobber (reg:CCFP FPSR_REG))
11433    (clobber (reg:CCFP FLAGS_REG))
11434    (clobber (match_scratch:HI 5))]
11435   "TARGET_80387 && !TARGET_CMOVE
11436    && reload_completed"
11437   [(const_int 0)]
11438 {
11439   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
11440                         operands[3], operands[4], operands[5]);
11441   DONE;
11442 })
11443
11444 ;; The order of operands in *jcc<fp>_<int>_i387 is forced by combine in
11445 ;; simplify_comparison () function. Float operator is treated as RTX_OBJ
11446 ;; with a precedence over other operators and is always put in the first
11447 ;; place. Swap condition and operands to match ficom instruction.
11448
11449 (define_insn "*jcc<X87MODEF:mode>_<SWI24:mode>_i387"
11450   [(set (pc)
11451         (if_then_else
11452           (match_operator:CCFP 0 "ix86_swapped_fp_comparison_operator"
11453             [(match_operator:X87MODEF 1 "float_operator"
11454               [(match_operand:SWI24 2 "nonimmediate_operand" "m")])
11455              (match_operand:X87MODEF 3 "register_operand" "f")])
11456           (label_ref (match_operand 4))
11457           (pc)))
11458    (clobber (reg:CCFP FPSR_REG))
11459    (clobber (reg:CCFP FLAGS_REG))
11460    (clobber (match_scratch:HI 5 "=a"))]
11461   "TARGET_80387 && !TARGET_CMOVE
11462    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
11463        || optimize_function_for_size_p (cfun))"
11464   "#")
11465
11466 (define_insn "*jcc<X87MODEF:mode>_<SWI24:mode>_r_i387"
11467   [(set (pc)
11468         (if_then_else
11469           (match_operator:CCFP 0 "ix86_swapped_fp_comparison_operator"
11470             [(match_operator:X87MODEF 1 "float_operator"
11471               [(match_operand:SWI24 2 "nonimmediate_operand" "m")])
11472              (match_operand:X87MODEF 3 "register_operand" "f")])
11473           (pc)
11474           (label_ref (match_operand 4))))
11475    (clobber (reg:CCFP FPSR_REG))
11476    (clobber (reg:CCFP FLAGS_REG))
11477    (clobber (match_scratch:HI 5 "=a"))]
11478   "TARGET_80387 && !TARGET_CMOVE
11479    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
11480        || optimize_function_for_size_p (cfun))"
11481   "#")
11482
11483 (define_split
11484   [(set (pc)
11485         (if_then_else
11486           (match_operator:CCFP 0 "ix86_swapped_fp_comparison_operator"
11487             [(match_operator:X87MODEF 1 "float_operator"
11488               [(match_operand:SWI24 2 "memory_operand")])
11489              (match_operand:X87MODEF 3 "register_operand")])
11490           (match_operand 4)
11491           (match_operand 5)))
11492    (clobber (reg:CCFP FPSR_REG))
11493    (clobber (reg:CCFP FLAGS_REG))
11494    (clobber (match_scratch:HI 6))]
11495   "TARGET_80387 && !TARGET_CMOVE
11496    && reload_completed"
11497   [(const_int 0)]
11498 {
11499   ix86_split_fp_branch (swap_condition (GET_CODE (operands[0])), operands[3],
11500                         gen_rtx_FLOAT (GET_MODE (operands[1]), operands[2]),
11501                         operands[4], operands[5], operands[6]);
11502   DONE;
11503 })
11504 \f
11505 ;; Unconditional and other jump instructions
11506
11507 (define_insn "jump_bnd"
11508   [(set (pc)
11509         (label_ref (match_operand 0)))]
11510   "TARGET_MPX && ix86_bnd_prefixed_insn_p (insn)"
11511   "bnd jmp\t%l0"
11512   [(set_attr "type" "ibr")
11513    (set (attr "length")
11514            (if_then_else (and (ge (minus (match_dup 0) (pc))
11515                                   (const_int -126))
11516                               (lt (minus (match_dup 0) (pc))
11517                                   (const_int 128)))
11518              (const_int 3)
11519              (const_int 6)))
11520    (set_attr "modrm" "0")])
11521
11522 (define_insn "jump"
11523   [(set (pc)
11524         (label_ref (match_operand 0)))]
11525   ""
11526   "jmp\t%l0"
11527   [(set_attr "type" "ibr")
11528    (set (attr "length")
11529            (if_then_else (and (ge (minus (match_dup 0) (pc))
11530                                   (const_int -126))
11531                               (lt (minus (match_dup 0) (pc))
11532                                   (const_int 128)))
11533              (const_int 2)
11534              (const_int 5)))
11535    (set_attr "modrm" "0")])
11536
11537 (define_expand "indirect_jump"
11538   [(set (pc) (match_operand 0 "indirect_branch_operand"))]
11539   ""
11540 {
11541   if (TARGET_X32)
11542     operands[0] = convert_memory_address (word_mode, operands[0]);
11543 })
11544
11545 (define_insn "*indirect_jump"
11546   [(set (pc) (match_operand:W 0 "indirect_branch_operand" "rBw"))]
11547   ""
11548   "%!jmp\t%A0"
11549   [(set_attr "type" "ibr")
11550    (set_attr "length_immediate" "0")])
11551
11552 (define_expand "tablejump"
11553   [(parallel [(set (pc) (match_operand 0 "indirect_branch_operand"))
11554               (use (label_ref (match_operand 1)))])]
11555   ""
11556 {
11557   /* In PIC mode, the table entries are stored GOT (32-bit) or PC (64-bit)
11558      relative.  Convert the relative address to an absolute address.  */
11559   if (flag_pic)
11560     {
11561       rtx op0, op1;
11562       enum rtx_code code;
11563
11564       /* We can't use @GOTOFF for text labels on VxWorks;
11565          see gotoff_operand.  */
11566       if (TARGET_64BIT || TARGET_VXWORKS_RTP)
11567         {
11568           code = PLUS;
11569           op0 = operands[0];
11570           op1 = gen_rtx_LABEL_REF (Pmode, operands[1]);
11571         }
11572       else if (TARGET_MACHO || HAVE_AS_GOTOFF_IN_DATA)
11573         {
11574           code = PLUS;
11575           op0 = operands[0];
11576           op1 = pic_offset_table_rtx;
11577         }
11578       else
11579         {
11580           code = MINUS;
11581           op0 = pic_offset_table_rtx;
11582           op1 = operands[0];
11583         }
11584
11585       operands[0] = expand_simple_binop (Pmode, code, op0, op1, NULL_RTX, 0,
11586                                          OPTAB_DIRECT);
11587     }
11588
11589   if (TARGET_X32)
11590     operands[0] = convert_memory_address (word_mode, operands[0]);
11591 })
11592
11593 (define_insn "*tablejump_1"
11594   [(set (pc) (match_operand:W 0 "indirect_branch_operand" "rBw"))
11595    (use (label_ref (match_operand 1)))]
11596   ""
11597   "%!jmp\t%A0"
11598   [(set_attr "type" "ibr")
11599    (set_attr "length_immediate" "0")])
11600 \f
11601 ;; Convert setcc + movzbl to xor + setcc if operands don't overlap.
11602
11603 (define_peephole2
11604   [(set (reg FLAGS_REG) (match_operand 0))
11605    (set (match_operand:QI 1 "register_operand")
11606         (match_operator:QI 2 "ix86_comparison_operator"
11607           [(reg FLAGS_REG) (const_int 0)]))
11608    (set (match_operand 3 "q_regs_operand")
11609         (zero_extend (match_dup 1)))]
11610   "(peep2_reg_dead_p (3, operands[1])
11611     || operands_match_p (operands[1], operands[3]))
11612    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11613   [(set (match_dup 4) (match_dup 0))
11614    (set (strict_low_part (match_dup 5))
11615         (match_dup 2))]
11616 {
11617   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11618   operands[5] = gen_lowpart (QImode, operands[3]);
11619   ix86_expand_clear (operands[3]);
11620 })
11621
11622 (define_peephole2
11623   [(parallel [(set (reg FLAGS_REG) (match_operand 0))
11624               (match_operand 4)])
11625    (set (match_operand:QI 1 "register_operand")
11626         (match_operator:QI 2 "ix86_comparison_operator"
11627           [(reg FLAGS_REG) (const_int 0)]))
11628    (set (match_operand 3 "q_regs_operand")
11629         (zero_extend (match_dup 1)))]
11630   "(peep2_reg_dead_p (3, operands[1])
11631     || operands_match_p (operands[1], operands[3]))
11632    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11633   [(parallel [(set (match_dup 5) (match_dup 0))
11634               (match_dup 4)])
11635    (set (strict_low_part (match_dup 6))
11636         (match_dup 2))]
11637 {
11638   operands[5] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11639   operands[6] = gen_lowpart (QImode, operands[3]);
11640   ix86_expand_clear (operands[3]);
11641 })
11642
11643 ;; Similar, but match zero extend with andsi3.
11644
11645 (define_peephole2
11646   [(set (reg FLAGS_REG) (match_operand 0))
11647    (set (match_operand:QI 1 "register_operand")
11648         (match_operator:QI 2 "ix86_comparison_operator"
11649           [(reg FLAGS_REG) (const_int 0)]))
11650    (parallel [(set (match_operand:SI 3 "q_regs_operand")
11651                    (and:SI (match_dup 3) (const_int 255)))
11652               (clobber (reg:CC FLAGS_REG))])]
11653   "REGNO (operands[1]) == REGNO (operands[3])
11654    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11655   [(set (match_dup 4) (match_dup 0))
11656    (set (strict_low_part (match_dup 5))
11657         (match_dup 2))]
11658 {
11659   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11660   operands[5] = gen_lowpart (QImode, operands[3]);
11661   ix86_expand_clear (operands[3]);
11662 })
11663
11664 (define_peephole2
11665   [(parallel [(set (reg FLAGS_REG) (match_operand 0))
11666               (match_operand 4)])
11667    (set (match_operand:QI 1 "register_operand")
11668         (match_operator:QI 2 "ix86_comparison_operator"
11669           [(reg FLAGS_REG) (const_int 0)]))
11670    (parallel [(set (match_operand 3 "q_regs_operand")
11671                    (zero_extend (match_dup 1)))
11672               (clobber (reg:CC FLAGS_REG))])]
11673   "(peep2_reg_dead_p (3, operands[1])
11674     || operands_match_p (operands[1], operands[3]))
11675    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11676   [(parallel [(set (match_dup 5) (match_dup 0))
11677               (match_dup 4)])
11678    (set (strict_low_part (match_dup 6))
11679         (match_dup 2))]
11680 {
11681   operands[5] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11682   operands[6] = gen_lowpart (QImode, operands[3]);
11683   ix86_expand_clear (operands[3]);
11684 })
11685 \f
11686 ;; Call instructions.
11687
11688 ;; The predicates normally associated with named expanders are not properly
11689 ;; checked for calls.  This is a bug in the generic code, but it isn't that
11690 ;; easy to fix.  Ignore it for now and be prepared to fix things up.
11691
11692 ;; P6 processors will jump to the address after the decrement when %esp
11693 ;; is used as a call operand, so they will execute return address as a code.
11694 ;; See Pentium Pro errata 70, Pentium 2 errata A33 and Pentium 3 errata E17.
11695
11696 ;; Register constraint for call instruction.
11697 (define_mode_attr c [(SI "l") (DI "r")])
11698
11699 ;; Call subroutine returning no value.
11700
11701 (define_expand "call"
11702   [(call (match_operand:QI 0)
11703          (match_operand 1))
11704    (use (match_operand 2))]
11705   ""
11706 {
11707   ix86_expand_call (NULL, operands[0], operands[1],
11708                     operands[2], NULL, false);
11709   DONE;
11710 })
11711
11712 (define_expand "sibcall"
11713   [(call (match_operand:QI 0)
11714          (match_operand 1))
11715    (use (match_operand 2))]
11716   ""
11717 {
11718   ix86_expand_call (NULL, operands[0], operands[1],
11719                     operands[2], NULL, true);
11720   DONE;
11721 })
11722
11723 (define_insn "*call"
11724   [(call (mem:QI (match_operand:W 0 "call_insn_operand" "<c>BwBz"))
11725          (match_operand 1))]
11726   "!SIBLING_CALL_P (insn)"
11727   "* return ix86_output_call_insn (insn, operands[0]);"
11728   [(set_attr "type" "call")])
11729
11730 (define_insn "*sibcall"
11731   [(call (mem:QI (match_operand:W 0 "sibcall_insn_operand" "UBsBz"))
11732          (match_operand 1))]
11733   "SIBLING_CALL_P (insn)"
11734   "* return ix86_output_call_insn (insn, operands[0]);"
11735   [(set_attr "type" "call")])
11736
11737 (define_insn "*sibcall_memory"
11738   [(call (mem:QI (match_operand:W 0 "memory_operand" "m"))
11739          (match_operand 1))
11740    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11741   "!TARGET_X32"
11742   "* return ix86_output_call_insn (insn, operands[0]);"
11743   [(set_attr "type" "call")])
11744
11745 (define_peephole2
11746   [(set (match_operand:W 0 "register_operand")
11747         (match_operand:W 1 "memory_operand"))
11748    (call (mem:QI (match_dup 0))
11749          (match_operand 3))]
11750   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1))
11751    && peep2_reg_dead_p (2, operands[0])"
11752   [(parallel [(call (mem:QI (match_dup 1))
11753                     (match_dup 3))
11754               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11755
11756 (define_peephole2
11757   [(set (match_operand:W 0 "register_operand")
11758         (match_operand:W 1 "memory_operand"))
11759    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11760    (call (mem:QI (match_dup 0))
11761          (match_operand 3))]
11762   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2))
11763    && peep2_reg_dead_p (3, operands[0])"
11764   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11765    (parallel [(call (mem:QI (match_dup 1))
11766                     (match_dup 3))
11767               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11768
11769 (define_expand "call_pop"
11770   [(parallel [(call (match_operand:QI 0)
11771                     (match_operand:SI 1))
11772               (set (reg:SI SP_REG)
11773                    (plus:SI (reg:SI SP_REG)
11774                             (match_operand:SI 3)))])]
11775   "!TARGET_64BIT"
11776 {
11777   ix86_expand_call (NULL, operands[0], operands[1],
11778                     operands[2], operands[3], false);
11779   DONE;
11780 })
11781
11782 (define_insn "*call_pop"
11783   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lmBz"))
11784          (match_operand 1))
11785    (set (reg:SI SP_REG)
11786         (plus:SI (reg:SI SP_REG)
11787                  (match_operand:SI 2 "immediate_operand" "i")))]
11788   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
11789   "* return ix86_output_call_insn (insn, operands[0]);"
11790   [(set_attr "type" "call")])
11791
11792 (define_insn "*sibcall_pop"
11793   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "UBsBz"))
11794          (match_operand 1))
11795    (set (reg:SI SP_REG)
11796         (plus:SI (reg:SI SP_REG)
11797                  (match_operand:SI 2 "immediate_operand" "i")))]
11798   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
11799   "* return ix86_output_call_insn (insn, operands[0]);"
11800   [(set_attr "type" "call")])
11801
11802 (define_insn "*sibcall_pop_memory"
11803   [(call (mem:QI (match_operand:SI 0 "memory_operand" "m"))
11804          (match_operand 1))
11805    (set (reg:SI SP_REG)
11806         (plus:SI (reg:SI SP_REG)
11807                  (match_operand:SI 2 "immediate_operand" "i")))
11808    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11809   "!TARGET_64BIT"
11810   "* return ix86_output_call_insn (insn, operands[0]);"
11811   [(set_attr "type" "call")])
11812
11813 (define_peephole2
11814   [(set (match_operand:SI 0 "register_operand")
11815         (match_operand:SI 1 "memory_operand"))
11816    (parallel [(call (mem:QI (match_dup 0))
11817                     (match_operand 3))
11818               (set (reg:SI SP_REG)
11819                    (plus:SI (reg:SI SP_REG)
11820                             (match_operand:SI 4 "immediate_operand")))])]
11821   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))
11822    && peep2_reg_dead_p (2, operands[0])"
11823   [(parallel [(call (mem:QI (match_dup 1))
11824                     (match_dup 3))
11825               (set (reg:SI SP_REG)
11826                    (plus:SI (reg:SI SP_REG)
11827                             (match_dup 4)))
11828               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11829
11830 (define_peephole2
11831   [(set (match_operand:SI 0 "register_operand")
11832         (match_operand:SI 1 "memory_operand"))
11833    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11834    (parallel [(call (mem:QI (match_dup 0))
11835                     (match_operand 3))
11836               (set (reg:SI SP_REG)
11837                    (plus:SI (reg:SI SP_REG)
11838                             (match_operand:SI 4 "immediate_operand")))])]
11839   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))
11840    && peep2_reg_dead_p (3, operands[0])"
11841   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11842    (parallel [(call (mem:QI (match_dup 1))
11843                     (match_dup 3))
11844               (set (reg:SI SP_REG)
11845                    (plus:SI (reg:SI SP_REG)
11846                             (match_dup 4)))
11847               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11848
11849 ;; Combining simple memory jump instruction
11850
11851 (define_peephole2
11852   [(set (match_operand:W 0 "register_operand")
11853         (match_operand:W 1 "memory_operand"))
11854    (set (pc) (match_dup 0))]
11855   "!TARGET_X32 && peep2_reg_dead_p (2, operands[0])"
11856   [(set (pc) (match_dup 1))])
11857
11858 ;; Call subroutine, returning value in operand 0
11859
11860 (define_expand "call_value"
11861   [(set (match_operand 0)
11862         (call (match_operand:QI 1)
11863               (match_operand 2)))
11864    (use (match_operand 3))]
11865   ""
11866 {
11867   ix86_expand_call (operands[0], operands[1], operands[2],
11868                     operands[3], NULL, false);
11869   DONE;
11870 })
11871
11872 (define_expand "sibcall_value"
11873   [(set (match_operand 0)
11874         (call (match_operand:QI 1)
11875               (match_operand 2)))
11876    (use (match_operand 3))]
11877   ""
11878 {
11879   ix86_expand_call (operands[0], operands[1], operands[2],
11880                     operands[3], NULL, true);
11881   DONE;
11882 })
11883
11884 (define_insn "*call_value"
11885   [(set (match_operand 0)
11886         (call (mem:QI (match_operand:W 1 "call_insn_operand" "<c>BwBz"))
11887               (match_operand 2)))]
11888   "!SIBLING_CALL_P (insn)"
11889   "* return ix86_output_call_insn (insn, operands[1]);"
11890   [(set_attr "type" "callv")])
11891
11892 (define_insn "*sibcall_value"
11893   [(set (match_operand 0)
11894         (call (mem:QI (match_operand:W 1 "sibcall_insn_operand" "UBsBz"))
11895               (match_operand 2)))]
11896   "SIBLING_CALL_P (insn)"
11897   "* return ix86_output_call_insn (insn, operands[1]);"
11898   [(set_attr "type" "callv")])
11899
11900 (define_insn "*sibcall_value_memory"
11901   [(set (match_operand 0)
11902         (call (mem:QI (match_operand:W 1 "memory_operand" "m"))
11903               (match_operand 2)))
11904    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11905   "!TARGET_X32"
11906   "* return ix86_output_call_insn (insn, operands[1]);"
11907   [(set_attr "type" "callv")])
11908
11909 (define_peephole2
11910   [(set (match_operand:W 0 "register_operand")
11911         (match_operand:W 1 "memory_operand"))
11912    (set (match_operand 2)
11913    (call (mem:QI (match_dup 0))
11914                  (match_operand 3)))]
11915   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1))
11916    && peep2_reg_dead_p (2, operands[0])"
11917   [(parallel [(set (match_dup 2)
11918                    (call (mem:QI (match_dup 1))
11919                          (match_dup 3)))
11920               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11921
11922 (define_peephole2
11923   [(set (match_operand:W 0 "register_operand")
11924         (match_operand:W 1 "memory_operand"))
11925    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11926    (set (match_operand 2)
11927         (call (mem:QI (match_dup 0))
11928               (match_operand 3)))]
11929   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2))
11930    && peep2_reg_dead_p (3, operands[0])"
11931   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11932    (parallel [(set (match_dup 2)
11933                    (call (mem:QI (match_dup 1))
11934                          (match_dup 3)))
11935               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11936
11937 (define_expand "call_value_pop"
11938   [(parallel [(set (match_operand 0)
11939                    (call (match_operand:QI 1)
11940                          (match_operand:SI 2)))
11941               (set (reg:SI SP_REG)
11942                    (plus:SI (reg:SI SP_REG)
11943                             (match_operand:SI 4)))])]
11944   "!TARGET_64BIT"
11945 {
11946   ix86_expand_call (operands[0], operands[1], operands[2],
11947                     operands[3], operands[4], false);
11948   DONE;
11949 })
11950
11951 (define_insn "*call_value_pop"
11952   [(set (match_operand 0)
11953         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lmBz"))
11954               (match_operand 2)))
11955    (set (reg:SI SP_REG)
11956         (plus:SI (reg:SI SP_REG)
11957                  (match_operand:SI 3 "immediate_operand" "i")))]
11958   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
11959   "* return ix86_output_call_insn (insn, operands[1]);"
11960   [(set_attr "type" "callv")])
11961
11962 (define_insn "*sibcall_value_pop"
11963   [(set (match_operand 0)
11964         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "UBsBz"))
11965               (match_operand 2)))
11966    (set (reg:SI SP_REG)
11967         (plus:SI (reg:SI SP_REG)
11968                  (match_operand:SI 3 "immediate_operand" "i")))]
11969   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
11970   "* return ix86_output_call_insn (insn, operands[1]);"
11971   [(set_attr "type" "callv")])
11972
11973 (define_insn "*sibcall_value_pop_memory"
11974   [(set (match_operand 0)
11975         (call (mem:QI (match_operand:SI 1 "memory_operand" "m"))
11976               (match_operand 2)))
11977    (set (reg:SI SP_REG)
11978         (plus:SI (reg:SI SP_REG)
11979                  (match_operand:SI 3 "immediate_operand" "i")))
11980    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11981   "!TARGET_64BIT"
11982   "* return ix86_output_call_insn (insn, operands[1]);"
11983   [(set_attr "type" "callv")])
11984
11985 (define_peephole2
11986   [(set (match_operand:SI 0 "register_operand")
11987         (match_operand:SI 1 "memory_operand"))
11988    (parallel [(set (match_operand 2)
11989                    (call (mem:QI (match_dup 0))
11990                          (match_operand 3)))
11991               (set (reg:SI SP_REG)
11992                    (plus:SI (reg:SI SP_REG)
11993                             (match_operand:SI 4 "immediate_operand")))])]
11994   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))
11995    && peep2_reg_dead_p (2, operands[0])"
11996   [(parallel [(set (match_dup 2)
11997                    (call (mem:QI (match_dup 1))
11998                          (match_dup 3)))
11999               (set (reg:SI SP_REG)
12000                    (plus:SI (reg:SI SP_REG)
12001                             (match_dup 4)))
12002               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
12003
12004 (define_peephole2
12005   [(set (match_operand:SI 0 "register_operand")
12006         (match_operand:SI 1 "memory_operand"))
12007    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
12008    (parallel [(set (match_operand 2)
12009                    (call (mem:QI (match_dup 0))
12010                          (match_operand 3)))
12011               (set (reg:SI SP_REG)
12012                    (plus:SI (reg:SI SP_REG)
12013                             (match_operand:SI 4 "immediate_operand")))])]
12014   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))
12015    && peep2_reg_dead_p (3, operands[0])"
12016   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
12017    (parallel [(set (match_dup 2)
12018                    (call (mem:QI (match_dup 1))
12019                          (match_dup 3)))
12020               (set (reg:SI SP_REG)
12021                    (plus:SI (reg:SI SP_REG)
12022                             (match_dup 4)))
12023               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
12024
12025 ;; Call subroutine returning any type.
12026
12027 (define_expand "untyped_call"
12028   [(parallel [(call (match_operand 0)
12029                     (const_int 0))
12030               (match_operand 1)
12031               (match_operand 2)])]
12032   ""
12033 {
12034   int i;
12035
12036   /* In order to give reg-stack an easier job in validating two
12037      coprocessor registers as containing a possible return value,
12038      simply pretend the untyped call returns a complex long double
12039      value. 
12040
12041      We can't use SSE_REGPARM_MAX here since callee is unprototyped
12042      and should have the default ABI.  */
12043
12044   ix86_expand_call ((TARGET_FLOAT_RETURNS_IN_80387
12045                      ? gen_rtx_REG (XCmode, FIRST_FLOAT_REG) : NULL),
12046                     operands[0], const0_rtx,
12047                     GEN_INT ((TARGET_64BIT
12048                               ? (ix86_abi == SYSV_ABI
12049                                  ? X86_64_SSE_REGPARM_MAX
12050                                  : X86_64_MS_SSE_REGPARM_MAX)
12051                               : X86_32_SSE_REGPARM_MAX)
12052                              - 1),
12053                     NULL, false);
12054
12055   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12056     {
12057       rtx set = XVECEXP (operands[2], 0, i);
12058       emit_move_insn (SET_DEST (set), SET_SRC (set));
12059     }
12060
12061   /* The optimizer does not know that the call sets the function value
12062      registers we stored in the result block.  We avoid problems by
12063      claiming that all hard registers are used and clobbered at this
12064      point.  */
12065   emit_insn (gen_blockage ());
12066
12067   DONE;
12068 })
12069 \f
12070 ;; Prologue and epilogue instructions
12071
12072 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12073 ;; all of memory.  This blocks insns from being moved across this point.
12074
12075 (define_insn "blockage"
12076   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
12077   ""
12078   ""
12079   [(set_attr "length" "0")])
12080
12081 ;; Do not schedule instructions accessing memory across this point.
12082
12083 (define_expand "memory_blockage"
12084   [(set (match_dup 0)
12085         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
12086   ""
12087 {
12088   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
12089   MEM_VOLATILE_P (operands[0]) = 1;
12090 })
12091
12092 (define_insn "*memory_blockage"
12093   [(set (match_operand:BLK 0)
12094         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
12095   ""
12096   ""
12097   [(set_attr "length" "0")])
12098
12099 ;; As USE insns aren't meaningful after reload, this is used instead
12100 ;; to prevent deleting instructions setting registers for PIC code
12101 (define_insn "prologue_use"
12102   [(unspec_volatile [(match_operand 0)] UNSPECV_PROLOGUE_USE)]
12103   ""
12104   ""
12105   [(set_attr "length" "0")])
12106
12107 ;; Insn emitted into the body of a function to return from a function.
12108 ;; This is only done if the function's epilogue is known to be simple.
12109 ;; See comments for ix86_can_use_return_insn_p in i386.c.
12110
12111 (define_expand "return"
12112   [(simple_return)]
12113   "ix86_can_use_return_insn_p ()"
12114 {
12115   if (crtl->args.pops_args)
12116     {
12117       rtx popc = GEN_INT (crtl->args.pops_args);
12118       emit_jump_insn (gen_simple_return_pop_internal (popc));
12119       DONE;
12120     }
12121 })
12122
12123 ;; We need to disable this for TARGET_SEH, as otherwise
12124 ;; shrink-wrapped prologue gets enabled too.  This might exceed
12125 ;; the maximum size of prologue in unwind information.
12126
12127 (define_expand "simple_return"
12128   [(simple_return)]
12129   "!TARGET_SEH"
12130 {
12131   if (crtl->args.pops_args)
12132     {
12133       rtx popc = GEN_INT (crtl->args.pops_args);
12134       emit_jump_insn (gen_simple_return_pop_internal (popc));
12135       DONE;
12136     }
12137 })
12138
12139 (define_insn "simple_return_internal"
12140   [(simple_return)]
12141   "reload_completed"
12142   "%!ret"
12143   [(set_attr "length_nobnd" "1")
12144    (set_attr "atom_unit" "jeu")
12145    (set_attr "length_immediate" "0")
12146    (set_attr "modrm" "0")])
12147
12148 ;; Used by x86_machine_dependent_reorg to avoid penalty on single byte RET
12149 ;; instruction Athlon and K8 have.
12150
12151 (define_insn "simple_return_internal_long"
12152   [(simple_return)
12153    (unspec [(const_int 0)] UNSPEC_REP)]
12154   "reload_completed"
12155 {
12156   if (ix86_bnd_prefixed_insn_p (insn))
12157     return "%!ret";
12158
12159   return "rep%; ret";
12160 }
12161   [(set_attr "length" "2")
12162    (set_attr "atom_unit" "jeu")
12163    (set_attr "length_immediate" "0")
12164    (set_attr "prefix_rep" "1")
12165    (set_attr "modrm" "0")])
12166
12167 (define_insn "simple_return_pop_internal"
12168   [(simple_return)
12169    (use (match_operand:SI 0 "const_int_operand"))]
12170   "reload_completed"
12171   "%!ret\t%0"
12172   [(set_attr "length_nobnd" "3")
12173    (set_attr "atom_unit" "jeu")
12174    (set_attr "length_immediate" "2")
12175    (set_attr "modrm" "0")])
12176
12177 (define_insn "simple_return_indirect_internal"
12178   [(simple_return)
12179    (use (match_operand:SI 0 "register_operand" "r"))]
12180   "reload_completed"
12181   "%!jmp\t%A0"
12182   [(set_attr "type" "ibr")
12183    (set_attr "length_immediate" "0")])
12184
12185 (define_insn "nop"
12186   [(const_int 0)]
12187   ""
12188   "nop"
12189   [(set_attr "length" "1")
12190    (set_attr "length_immediate" "0")
12191    (set_attr "modrm" "0")])
12192
12193 ;; Generate nops.  Operand 0 is the number of nops, up to 8.
12194 (define_insn "nops"
12195   [(unspec_volatile [(match_operand 0 "const_int_operand")]
12196                     UNSPECV_NOPS)]
12197   "reload_completed"
12198 {
12199   int num = INTVAL (operands[0]);
12200
12201   gcc_assert (IN_RANGE (num, 1, 8));
12202
12203   while (num--)
12204     fputs ("\tnop\n", asm_out_file);
12205
12206   return "";
12207 }
12208   [(set (attr "length") (symbol_ref "INTVAL (operands[0])"))
12209    (set_attr "length_immediate" "0")
12210    (set_attr "modrm" "0")])
12211
12212 ;; Pad to 16-byte boundary, max skip in op0.  Used to avoid
12213 ;; branch prediction penalty for the third jump in a 16-byte
12214 ;; block on K8.
12215
12216 (define_insn "pad"
12217   [(unspec_volatile [(match_operand 0)] UNSPECV_ALIGN)]
12218   ""
12219 {
12220 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
12221   ASM_OUTPUT_MAX_SKIP_PAD (asm_out_file, 4, (int)INTVAL (operands[0]));
12222 #else
12223   /* It is tempting to use ASM_OUTPUT_ALIGN here, but we don't want to do that.
12224      The align insn is used to avoid 3 jump instructions in the row to improve
12225      branch prediction and the benefits hardly outweigh the cost of extra 8
12226      nops on the average inserted by full alignment pseudo operation.  */
12227 #endif
12228   return "";
12229 }
12230   [(set_attr "length" "16")])
12231
12232 (define_expand "prologue"
12233   [(const_int 0)]
12234   ""
12235   "ix86_expand_prologue (); DONE;")
12236
12237 (define_insn "set_got"
12238   [(set (match_operand:SI 0 "register_operand" "=r")
12239         (unspec:SI [(const_int 0)] UNSPEC_SET_GOT))
12240    (clobber (reg:CC FLAGS_REG))]
12241   "!TARGET_64BIT"
12242   "* return output_set_got (operands[0], NULL_RTX);"
12243   [(set_attr "type" "multi")
12244    (set_attr "length" "12")])
12245
12246 (define_insn "set_got_labelled"
12247   [(set (match_operand:SI 0 "register_operand" "=r")
12248         (unspec:SI [(label_ref (match_operand 1))]
12249          UNSPEC_SET_GOT))
12250    (clobber (reg:CC FLAGS_REG))]
12251   "!TARGET_64BIT"
12252   "* return output_set_got (operands[0], operands[1]);"
12253   [(set_attr "type" "multi")
12254    (set_attr "length" "12")])
12255
12256 (define_insn "set_got_rex64"
12257   [(set (match_operand:DI 0 "register_operand" "=r")
12258         (unspec:DI [(const_int 0)] UNSPEC_SET_GOT))]
12259   "TARGET_64BIT"
12260   "lea{q}\t{_GLOBAL_OFFSET_TABLE_(%%rip), %0|%0, _GLOBAL_OFFSET_TABLE_[rip]}"
12261   [(set_attr "type" "lea")
12262    (set_attr "length_address" "4")
12263    (set_attr "mode" "DI")])
12264
12265 (define_insn "set_rip_rex64"
12266   [(set (match_operand:DI 0 "register_operand" "=r")
12267         (unspec:DI [(label_ref (match_operand 1))] UNSPEC_SET_RIP))]
12268   "TARGET_64BIT"
12269   "lea{q}\t{%l1(%%rip), %0|%0, %l1[rip]}"
12270   [(set_attr "type" "lea")
12271    (set_attr "length_address" "4")
12272    (set_attr "mode" "DI")])
12273
12274 (define_insn "set_got_offset_rex64"
12275   [(set (match_operand:DI 0 "register_operand" "=r")
12276         (unspec:DI
12277           [(label_ref (match_operand 1))]
12278           UNSPEC_SET_GOT_OFFSET))]
12279   "TARGET_LP64"
12280   "movabs{q}\t{$_GLOBAL_OFFSET_TABLE_-%l1, %0|%0, OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-%l1}"
12281   [(set_attr "type" "imov")
12282    (set_attr "length_immediate" "0")
12283    (set_attr "length_address" "8")
12284    (set_attr "mode" "DI")])
12285
12286 (define_expand "epilogue"
12287   [(const_int 0)]
12288   ""
12289   "ix86_expand_epilogue (1); DONE;")
12290
12291 (define_expand "sibcall_epilogue"
12292   [(const_int 0)]
12293   ""
12294   "ix86_expand_epilogue (0); DONE;")
12295
12296 (define_expand "eh_return"
12297   [(use (match_operand 0 "register_operand"))]
12298   ""
12299 {
12300   rtx tmp, sa = EH_RETURN_STACKADJ_RTX, ra = operands[0];
12301
12302   /* Tricky bit: we write the address of the handler to which we will
12303      be returning into someone else's stack frame, one word below the
12304      stack address we wish to restore.  */
12305   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
12306   tmp = plus_constant (Pmode, tmp, -UNITS_PER_WORD);
12307   tmp = gen_rtx_MEM (Pmode, tmp);
12308   emit_move_insn (tmp, ra);
12309
12310   emit_jump_insn (gen_eh_return_internal ());
12311   emit_barrier ();
12312   DONE;
12313 })
12314
12315 (define_insn_and_split "eh_return_internal"
12316   [(eh_return)]
12317   ""
12318   "#"
12319   "epilogue_completed"
12320   [(const_int 0)]
12321   "ix86_expand_epilogue (2); DONE;")
12322
12323 (define_insn "leave"
12324   [(set (reg:SI SP_REG) (plus:SI (reg:SI BP_REG) (const_int 4)))
12325    (set (reg:SI BP_REG) (mem:SI (reg:SI BP_REG)))
12326    (clobber (mem:BLK (scratch)))]
12327   "!TARGET_64BIT"
12328   "leave"
12329   [(set_attr "type" "leave")])
12330
12331 (define_insn "leave_rex64"
12332   [(set (reg:DI SP_REG) (plus:DI (reg:DI BP_REG) (const_int 8)))
12333    (set (reg:DI BP_REG) (mem:DI (reg:DI BP_REG)))
12334    (clobber (mem:BLK (scratch)))]
12335   "TARGET_64BIT"
12336   "leave"
12337   [(set_attr "type" "leave")])
12338 \f
12339 ;; Handle -fsplit-stack.
12340
12341 (define_expand "split_stack_prologue"
12342   [(const_int 0)]
12343   ""
12344 {
12345   ix86_expand_split_stack_prologue ();
12346   DONE;
12347 })
12348
12349 ;; In order to support the call/return predictor, we use a return
12350 ;; instruction which the middle-end doesn't see.
12351 (define_insn "split_stack_return"
12352   [(unspec_volatile [(match_operand:SI 0 "const_int_operand")]
12353                      UNSPECV_SPLIT_STACK_RETURN)]
12354   ""
12355 {
12356   if (operands[0] == const0_rtx)
12357     return "ret";
12358   else
12359     return "ret\t%0";
12360 }
12361   [(set_attr "atom_unit" "jeu")
12362    (set_attr "modrm" "0")
12363    (set (attr "length")
12364         (if_then_else (match_operand:SI 0 "const0_operand")
12365                       (const_int 1)
12366                       (const_int 3)))
12367    (set (attr "length_immediate")
12368         (if_then_else (match_operand:SI 0 "const0_operand")
12369                       (const_int 0)
12370                       (const_int 2)))])
12371
12372 ;; If there are operand 0 bytes available on the stack, jump to
12373 ;; operand 1.
12374
12375 (define_expand "split_stack_space_check"
12376   [(set (pc) (if_then_else
12377               (ltu (minus (reg SP_REG)
12378                           (match_operand 0 "register_operand"))
12379                    (unspec [(const_int 0)] UNSPEC_STACK_CHECK))
12380               (label_ref (match_operand 1))
12381               (pc)))]
12382   ""
12383 {
12384   rtx reg, size, limit;
12385
12386   reg = gen_reg_rtx (Pmode);
12387   size = force_reg (Pmode, operands[0]);
12388   emit_insn (gen_sub3_insn (reg, stack_pointer_rtx, size));
12389   limit = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
12390                           UNSPEC_STACK_CHECK);
12391   limit = gen_rtx_MEM (Pmode, gen_rtx_CONST (Pmode, limit));
12392   ix86_expand_branch (GEU, reg, limit, operands[1]);
12393
12394   DONE;
12395 })
12396 \f
12397 ;; Bit manipulation instructions.
12398
12399 (define_expand "ffs<mode>2"
12400   [(set (match_dup 2) (const_int -1))
12401    (parallel [(set (match_dup 3) (match_dup 4))
12402               (set (match_operand:SWI48 0 "register_operand")
12403                    (ctz:SWI48
12404                      (match_operand:SWI48 1 "nonimmediate_operand")))])
12405    (set (match_dup 0) (if_then_else:SWI48
12406                         (eq (match_dup 3) (const_int 0))
12407                         (match_dup 2)
12408                         (match_dup 0)))
12409    (parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (const_int 1)))
12410               (clobber (reg:CC FLAGS_REG))])]
12411   ""
12412 {
12413   machine_mode flags_mode;
12414
12415   if (<MODE>mode == SImode && !TARGET_CMOVE)
12416     {
12417       emit_insn (gen_ffssi2_no_cmove (operands[0], operands [1]));
12418       DONE;
12419     }
12420
12421   flags_mode
12422     = (TARGET_BMI && !TARGET_AVOID_FALSE_DEP_FOR_BMI) ? CCCmode : CCZmode;
12423
12424   operands[2] = gen_reg_rtx (<MODE>mode);
12425   operands[3] = gen_rtx_REG (flags_mode, FLAGS_REG);
12426   operands[4] = gen_rtx_COMPARE (flags_mode, operands[1], const0_rtx);
12427 })
12428
12429 (define_insn_and_split "ffssi2_no_cmove"
12430   [(set (match_operand:SI 0 "register_operand" "=r")
12431         (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
12432    (clobber (match_scratch:SI 2 "=&q"))
12433    (clobber (reg:CC FLAGS_REG))]
12434   "!TARGET_CMOVE"
12435   "#"
12436   "&& reload_completed"
12437   [(parallel [(set (match_dup 4) (match_dup 5))
12438               (set (match_dup 0) (ctz:SI (match_dup 1)))])
12439    (set (strict_low_part (match_dup 3))
12440         (eq:QI (match_dup 4) (const_int 0)))
12441    (parallel [(set (match_dup 2) (neg:SI (match_dup 2)))
12442               (clobber (reg:CC FLAGS_REG))])
12443    (parallel [(set (match_dup 0) (ior:SI (match_dup 0) (match_dup 2)))
12444               (clobber (reg:CC FLAGS_REG))])
12445    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
12446               (clobber (reg:CC FLAGS_REG))])]
12447 {
12448   machine_mode flags_mode
12449     = (TARGET_BMI && !TARGET_AVOID_FALSE_DEP_FOR_BMI) ? CCCmode : CCZmode;
12450
12451   operands[3] = gen_lowpart (QImode, operands[2]);
12452   operands[4] = gen_rtx_REG (flags_mode, FLAGS_REG);
12453   operands[5] = gen_rtx_COMPARE (flags_mode, operands[1], const0_rtx);
12454
12455   ix86_expand_clear (operands[2]);
12456 })
12457
12458 (define_insn "*tzcnt<mode>_1"
12459   [(set (reg:CCC FLAGS_REG)
12460         (compare:CCC (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12461                      (const_int 0)))
12462    (set (match_operand:SWI48 0 "register_operand" "=r")
12463         (ctz:SWI48 (match_dup 1)))]
12464   "TARGET_BMI && !TARGET_AVOID_FALSE_DEP_FOR_BMI"
12465   "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}"
12466   [(set_attr "type" "alu1")
12467    (set_attr "prefix_0f" "1")
12468    (set_attr "prefix_rep" "1")
12469    (set_attr "btver2_decode" "double")
12470    (set_attr "mode" "<MODE>")])
12471
12472 (define_insn "*bsf<mode>_1"
12473   [(set (reg:CCZ FLAGS_REG)
12474         (compare:CCZ (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12475                      (const_int 0)))
12476    (set (match_operand:SWI48 0 "register_operand" "=r")
12477         (ctz:SWI48 (match_dup 1)))]
12478   ""
12479   "bsf{<imodesuffix>}\t{%1, %0|%0, %1}"
12480   [(set_attr "type" "alu1")
12481    (set_attr "prefix_0f" "1")
12482    (set_attr "btver2_decode" "double")
12483    (set_attr "mode" "<MODE>")])
12484
12485 (define_expand "ctz<mode>2"
12486   [(parallel
12487     [(set (match_operand:SWI248 0 "register_operand")
12488           (ctz:SWI248
12489             (match_operand:SWI248 1 "nonimmediate_operand")))
12490      (clobber (reg:CC FLAGS_REG))])])
12491
12492 ; False dependency happens when destination is only updated by tzcnt,
12493 ; lzcnt or popcnt.  There is no false dependency when destination is
12494 ; also used in source.
12495 (define_insn_and_split "*ctz<mode>2_falsedep_1"
12496   [(set (match_operand:SWI48 0 "register_operand" "=r")
12497         (ctz:SWI48
12498           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12499    (clobber (reg:CC FLAGS_REG))]
12500   "(TARGET_BMI || TARGET_GENERIC)
12501    && TARGET_AVOID_FALSE_DEP_FOR_BMI && optimize_function_for_speed_p (cfun)"
12502   "#"
12503   "&& reload_completed"
12504   [(parallel
12505     [(set (match_dup 0)
12506           (ctz:SWI48 (match_dup 1)))
12507      (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)
12508      (clobber (reg:CC FLAGS_REG))])]
12509 {
12510   if (!reg_mentioned_p (operands[0], operands[1]))
12511     ix86_expand_clear (operands[0]);
12512 })
12513
12514 (define_insn "*ctz<mode>2_falsedep"
12515   [(set (match_operand:SWI48 0 "register_operand" "=r")
12516         (ctz:SWI48
12517           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12518    (unspec [(match_operand:SWI48 2 "register_operand" "0")]
12519            UNSPEC_INSN_FALSE_DEP)
12520    (clobber (reg:CC FLAGS_REG))]
12521   ""
12522 {
12523   if (TARGET_BMI)
12524     return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12525   else if (TARGET_GENERIC)
12526     /* tzcnt expands to 'rep bsf' and we can use it even if !TARGET_BMI.  */
12527     return "rep%; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
12528   else
12529     gcc_unreachable ();
12530 }
12531   [(set_attr "type" "alu1")
12532    (set_attr "prefix_0f" "1")
12533    (set_attr "prefix_rep" "1")
12534    (set_attr "mode" "<MODE>")])
12535
12536 (define_insn "*ctz<mode>2"
12537   [(set (match_operand:SWI248 0 "register_operand" "=r")
12538         (ctz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12539    (clobber (reg:CC FLAGS_REG))]
12540   ""
12541 {
12542   if (TARGET_BMI)
12543     return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12544   else if (optimize_function_for_size_p (cfun))
12545     ;
12546   else if (TARGET_GENERIC)
12547     /* tzcnt expands to 'rep bsf' and we can use it even if !TARGET_BMI.  */
12548     return "rep%; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
12549
12550   return "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
12551 }
12552   [(set_attr "type" "alu1")
12553    (set_attr "prefix_0f" "1")
12554    (set (attr "prefix_rep")
12555      (if_then_else
12556        (ior (match_test "TARGET_BMI")
12557             (and (not (match_test "optimize_function_for_size_p (cfun)"))
12558                  (match_test "TARGET_GENERIC")))
12559        (const_string "1")
12560        (const_string "0")))
12561    (set_attr "mode" "<MODE>")])
12562
12563 (define_expand "clz<mode>2"
12564   [(parallel
12565      [(set (match_operand:SWI248 0 "register_operand")
12566            (minus:SWI248
12567              (match_dup 2)
12568              (clz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand"))))
12569       (clobber (reg:CC FLAGS_REG))])
12570    (parallel
12571      [(set (match_dup 0) (xor:SWI248 (match_dup 0) (match_dup 2)))
12572       (clobber (reg:CC FLAGS_REG))])]
12573   ""
12574 {
12575   if (TARGET_LZCNT)
12576     {
12577       emit_insn (gen_clz<mode>2_lzcnt (operands[0], operands[1]));
12578       DONE;
12579     }
12580   operands[2] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
12581 })
12582
12583 (define_expand "clz<mode>2_lzcnt"
12584   [(parallel
12585     [(set (match_operand:SWI248 0 "register_operand")
12586           (clz:SWI248
12587             (match_operand:SWI248 1 "nonimmediate_operand")))
12588      (clobber (reg:CC FLAGS_REG))])]
12589   "TARGET_LZCNT")
12590
12591 (define_insn_and_split "*clz<mode>2_lzcnt_falsedep_1"
12592   [(set (match_operand:SWI48 0 "register_operand" "=r")
12593         (clz:SWI48
12594           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12595    (clobber (reg:CC FLAGS_REG))]
12596   "TARGET_LZCNT
12597    && TARGET_AVOID_FALSE_DEP_FOR_BMI && optimize_function_for_speed_p (cfun)"
12598   "#"
12599   "&& reload_completed"
12600   [(parallel
12601     [(set (match_dup 0)
12602           (clz:SWI48 (match_dup 1)))
12603      (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)
12604      (clobber (reg:CC FLAGS_REG))])]
12605 {
12606   if (!reg_mentioned_p (operands[0], operands[1]))
12607     ix86_expand_clear (operands[0]);
12608 })
12609
12610 (define_insn "*clz<mode>2_lzcnt_falsedep"
12611   [(set (match_operand:SWI48 0 "register_operand" "=r")
12612         (clz:SWI48
12613           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12614    (unspec [(match_operand:SWI48 2 "register_operand" "0")]
12615            UNSPEC_INSN_FALSE_DEP)
12616    (clobber (reg:CC FLAGS_REG))]
12617   "TARGET_LZCNT"
12618   "lzcnt{<imodesuffix>}\t{%1, %0|%0, %1}"
12619   [(set_attr "prefix_rep" "1")
12620    (set_attr "type" "bitmanip")
12621    (set_attr "mode" "<MODE>")])
12622
12623 (define_insn "*clz<mode>2_lzcnt"
12624   [(set (match_operand:SWI248 0 "register_operand" "=r")
12625         (clz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12626    (clobber (reg:CC FLAGS_REG))]
12627   "TARGET_LZCNT"
12628   "lzcnt{<imodesuffix>}\t{%1, %0|%0, %1}"
12629   [(set_attr "prefix_rep" "1")
12630    (set_attr "type" "bitmanip")
12631    (set_attr "mode" "<MODE>")])
12632
12633 ;; BMI instructions.
12634 (define_insn "*bmi_andn_<mode>"
12635   [(set (match_operand:SWI48 0 "register_operand" "=r,r")
12636         (and:SWI48
12637           (not:SWI48
12638             (match_operand:SWI48 1 "register_operand" "r,r"))
12639             (match_operand:SWI48 2 "nonimmediate_operand" "r,m")))
12640    (clobber (reg:CC FLAGS_REG))]
12641   "TARGET_BMI"
12642   "andn\t{%2, %1, %0|%0, %1, %2}"
12643   [(set_attr "type" "bitmanip")
12644    (set_attr "btver2_decode" "direct, double")
12645    (set_attr "mode" "<MODE>")])
12646
12647 (define_insn "bmi_bextr_<mode>"
12648   [(set (match_operand:SWI48 0 "register_operand" "=r,r")
12649         (unspec:SWI48 [(match_operand:SWI48 1 "nonimmediate_operand" "r,m")
12650                        (match_operand:SWI48 2 "register_operand" "r,r")]
12651                        UNSPEC_BEXTR))
12652    (clobber (reg:CC FLAGS_REG))]
12653   "TARGET_BMI"
12654   "bextr\t{%2, %1, %0|%0, %1, %2}"
12655   [(set_attr "type" "bitmanip")
12656    (set_attr "btver2_decode" "direct, double")
12657    (set_attr "mode" "<MODE>")])
12658
12659 (define_insn "*bmi_blsi_<mode>"
12660   [(set (match_operand:SWI48 0 "register_operand" "=r")
12661         (and:SWI48
12662           (neg:SWI48
12663             (match_operand:SWI48 1 "nonimmediate_operand" "rm"))
12664           (match_dup 1)))
12665    (clobber (reg:CC FLAGS_REG))]
12666   "TARGET_BMI"
12667   "blsi\t{%1, %0|%0, %1}"
12668   [(set_attr "type" "bitmanip")
12669    (set_attr "btver2_decode" "double")
12670    (set_attr "mode" "<MODE>")])
12671
12672 (define_insn "*bmi_blsmsk_<mode>"
12673   [(set (match_operand:SWI48 0 "register_operand" "=r")
12674         (xor:SWI48
12675           (plus:SWI48
12676             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12677             (const_int -1))
12678           (match_dup 1)))
12679    (clobber (reg:CC FLAGS_REG))]
12680   "TARGET_BMI"
12681   "blsmsk\t{%1, %0|%0, %1}"
12682   [(set_attr "type" "bitmanip")
12683    (set_attr "btver2_decode" "double")
12684    (set_attr "mode" "<MODE>")])
12685
12686 (define_insn "*bmi_blsr_<mode>"
12687   [(set (match_operand:SWI48 0 "register_operand" "=r")
12688         (and:SWI48
12689           (plus:SWI48
12690             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12691             (const_int -1))
12692           (match_dup 1)))
12693    (clobber (reg:CC FLAGS_REG))]
12694    "TARGET_BMI"
12695    "blsr\t{%1, %0|%0, %1}"
12696   [(set_attr "type" "bitmanip")
12697    (set_attr "btver2_decode" "double")
12698    (set_attr "mode" "<MODE>")])
12699
12700 ;; BMI2 instructions.
12701 (define_expand "bmi2_bzhi_<mode>3"
12702   [(parallel
12703     [(set (match_operand:SWI48 0 "register_operand")
12704           (zero_extract:SWI48
12705             (match_operand:SWI48 1 "nonimmediate_operand")
12706             (umin:SWI48
12707               (and:SWI48 (match_operand:SWI48 2 "register_operand")
12708                          (const_int 255))
12709               (match_dup 3))
12710             (const_int 0)))
12711      (clobber (reg:CC FLAGS_REG))])]
12712   "TARGET_BMI2"
12713   "operands[3] = GEN_INT (<MODE_SIZE> * BITS_PER_UNIT);")
12714
12715 (define_insn "*bmi2_bzhi_<mode>3"
12716   [(set (match_operand:SWI48 0 "register_operand" "=r")
12717         (zero_extract:SWI48
12718           (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12719           (umin:SWI48
12720             (and:SWI48 (match_operand:SWI48 2 "register_operand" "r")
12721                        (const_int 255))
12722             (match_operand:SWI48 3 "const_int_operand" "n"))
12723           (const_int 0)))
12724    (clobber (reg:CC FLAGS_REG))]
12725   "TARGET_BMI2 && INTVAL (operands[3]) == <MODE_SIZE> * BITS_PER_UNIT"
12726   "bzhi\t{%2, %1, %0|%0, %1, %2}"
12727   [(set_attr "type" "bitmanip")
12728    (set_attr "prefix" "vex")
12729    (set_attr "mode" "<MODE>")])
12730
12731 (define_mode_attr k [(SI "k") (DI "q")])
12732 (define_insn "*bmi2_bzhi_<mode>3_1"
12733   [(set (match_operand:SWI48 0 "register_operand" "=r")
12734         (zero_extract:SWI48
12735           (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12736           (umin:SWI48
12737             (zero_extend:SWI48 (match_operand:QI 2 "register_operand" "r"))
12738             (match_operand:SWI48 3 "const_int_operand" "n"))
12739           (const_int 0)))
12740    (clobber (reg:CC FLAGS_REG))]
12741   "TARGET_BMI2 && INTVAL (operands[3]) == <MODE_SIZE> * BITS_PER_UNIT"
12742   "bzhi\t{%<k>2, %1, %0|%0, %1, %<k>2}"
12743   [(set_attr "type" "bitmanip")
12744    (set_attr "prefix" "vex")
12745    (set_attr "mode" "<MODE>")])
12746
12747 (define_insn "bmi2_pdep_<mode>3"
12748   [(set (match_operand:SWI48 0 "register_operand" "=r")
12749         (unspec:SWI48 [(match_operand:SWI48 1 "register_operand" "r")
12750                        (match_operand:SWI48 2 "nonimmediate_operand" "rm")]
12751                        UNSPEC_PDEP))]
12752   "TARGET_BMI2"
12753   "pdep\t{%2, %1, %0|%0, %1, %2}"
12754   [(set_attr "type" "bitmanip")
12755    (set_attr "prefix" "vex")
12756    (set_attr "mode" "<MODE>")])
12757
12758 (define_insn "bmi2_pext_<mode>3"
12759   [(set (match_operand:SWI48 0 "register_operand" "=r")
12760         (unspec:SWI48 [(match_operand:SWI48 1 "register_operand" "r")
12761                        (match_operand:SWI48 2 "nonimmediate_operand" "rm")]
12762                        UNSPEC_PEXT))]
12763   "TARGET_BMI2"
12764   "pext\t{%2, %1, %0|%0, %1, %2}"
12765   [(set_attr "type" "bitmanip")
12766    (set_attr "prefix" "vex")
12767    (set_attr "mode" "<MODE>")])
12768
12769 ;; TBM instructions.
12770 (define_insn "tbm_bextri_<mode>"
12771   [(set (match_operand:SWI48 0 "register_operand" "=r")
12772         (zero_extract:SWI48
12773           (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12774           (match_operand:SWI48 2 "const_0_to_255_operand" "n")
12775           (match_operand:SWI48 3 "const_0_to_255_operand" "n")))
12776    (clobber (reg:CC FLAGS_REG))]
12777    "TARGET_TBM"
12778 {
12779   operands[2] = GEN_INT (INTVAL (operands[2]) << 8 | INTVAL (operands[3]));
12780   return "bextr\t{%2, %1, %0|%0, %1, %2}";
12781 }
12782   [(set_attr "type" "bitmanip")
12783    (set_attr "mode" "<MODE>")])
12784
12785 (define_insn "*tbm_blcfill_<mode>"
12786   [(set (match_operand:SWI48 0 "register_operand" "=r")
12787         (and:SWI48
12788           (plus:SWI48
12789             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12790             (const_int 1))
12791           (match_dup 1)))
12792    (clobber (reg:CC FLAGS_REG))]
12793    "TARGET_TBM"
12794    "blcfill\t{%1, %0|%0, %1}"
12795   [(set_attr "type" "bitmanip")
12796    (set_attr "mode" "<MODE>")])
12797
12798 (define_insn "*tbm_blci_<mode>"
12799   [(set (match_operand:SWI48 0 "register_operand" "=r")
12800         (ior:SWI48
12801           (not:SWI48
12802             (plus:SWI48
12803               (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12804               (const_int 1)))
12805           (match_dup 1)))
12806    (clobber (reg:CC FLAGS_REG))]
12807    "TARGET_TBM"
12808    "blci\t{%1, %0|%0, %1}"
12809   [(set_attr "type" "bitmanip")
12810    (set_attr "mode" "<MODE>")])
12811
12812 (define_insn "*tbm_blcic_<mode>"
12813   [(set (match_operand:SWI48 0 "register_operand" "=r")
12814         (and:SWI48
12815           (plus:SWI48
12816             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12817             (const_int 1))
12818           (not:SWI48
12819             (match_dup 1))))
12820    (clobber (reg:CC FLAGS_REG))]
12821    "TARGET_TBM"
12822    "blcic\t{%1, %0|%0, %1}"
12823   [(set_attr "type" "bitmanip")
12824    (set_attr "mode" "<MODE>")])
12825
12826 (define_insn "*tbm_blcmsk_<mode>"
12827   [(set (match_operand:SWI48 0 "register_operand" "=r")
12828         (xor:SWI48
12829           (plus:SWI48
12830             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12831             (const_int 1))
12832           (match_dup 1)))
12833    (clobber (reg:CC FLAGS_REG))]
12834    "TARGET_TBM"
12835    "blcmsk\t{%1, %0|%0, %1}"
12836   [(set_attr "type" "bitmanip")
12837    (set_attr "mode" "<MODE>")])
12838
12839 (define_insn "*tbm_blcs_<mode>"
12840   [(set (match_operand:SWI48 0 "register_operand" "=r")
12841         (ior:SWI48
12842           (plus:SWI48
12843             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12844             (const_int 1))
12845           (match_dup 1)))
12846    (clobber (reg:CC FLAGS_REG))]
12847    "TARGET_TBM"
12848    "blcs\t{%1, %0|%0, %1}"
12849   [(set_attr "type" "bitmanip")
12850    (set_attr "mode" "<MODE>")])
12851
12852 (define_insn "*tbm_blsfill_<mode>"
12853   [(set (match_operand:SWI48 0 "register_operand" "=r")
12854         (ior:SWI48
12855           (plus:SWI48
12856             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12857             (const_int -1))
12858           (match_dup 1)))
12859    (clobber (reg:CC FLAGS_REG))]
12860    "TARGET_TBM"
12861    "blsfill\t{%1, %0|%0, %1}"
12862   [(set_attr "type" "bitmanip")
12863    (set_attr "mode" "<MODE>")])
12864
12865 (define_insn "*tbm_blsic_<mode>"
12866   [(set (match_operand:SWI48 0 "register_operand" "=r")
12867         (ior:SWI48
12868           (plus:SWI48
12869             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12870             (const_int -1))
12871           (not:SWI48
12872             (match_dup 1))))
12873    (clobber (reg:CC FLAGS_REG))]
12874    "TARGET_TBM"
12875    "blsic\t{%1, %0|%0, %1}"
12876   [(set_attr "type" "bitmanip")
12877    (set_attr "mode" "<MODE>")])
12878
12879 (define_insn "*tbm_t1mskc_<mode>"
12880   [(set (match_operand:SWI48 0 "register_operand" "=r")
12881         (ior:SWI48
12882           (plus:SWI48
12883             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12884             (const_int 1))
12885           (not:SWI48
12886             (match_dup 1))))
12887    (clobber (reg:CC FLAGS_REG))]
12888    "TARGET_TBM"
12889    "t1mskc\t{%1, %0|%0, %1}"
12890   [(set_attr "type" "bitmanip")
12891    (set_attr "mode" "<MODE>")])
12892
12893 (define_insn "*tbm_tzmsk_<mode>"
12894   [(set (match_operand:SWI48 0 "register_operand" "=r")
12895         (and:SWI48
12896           (plus:SWI48
12897             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12898             (const_int -1))
12899           (not:SWI48
12900             (match_dup 1))))
12901    (clobber (reg:CC FLAGS_REG))]
12902    "TARGET_TBM"
12903    "tzmsk\t{%1, %0|%0, %1}"
12904   [(set_attr "type" "bitmanip")
12905    (set_attr "mode" "<MODE>")])
12906
12907 (define_insn "bsr_rex64"
12908   [(set (match_operand:DI 0 "register_operand" "=r")
12909         (minus:DI (const_int 63)
12910                   (clz:DI (match_operand:DI 1 "nonimmediate_operand" "rm"))))
12911    (clobber (reg:CC FLAGS_REG))]
12912   "TARGET_64BIT"
12913   "bsr{q}\t{%1, %0|%0, %1}"
12914   [(set_attr "type" "alu1")
12915    (set_attr "prefix_0f" "1")
12916    (set_attr "mode" "DI")])
12917
12918 (define_insn "bsr"
12919   [(set (match_operand:SI 0 "register_operand" "=r")
12920         (minus:SI (const_int 31)
12921                   (clz:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))))
12922    (clobber (reg:CC FLAGS_REG))]
12923   ""
12924   "bsr{l}\t{%1, %0|%0, %1}"
12925   [(set_attr "type" "alu1")
12926    (set_attr "prefix_0f" "1")
12927    (set_attr "mode" "SI")])
12928
12929 (define_insn "*bsrhi"
12930   [(set (match_operand:HI 0 "register_operand" "=r")
12931         (minus:HI (const_int 15)
12932                   (clz:HI (match_operand:HI 1 "nonimmediate_operand" "rm"))))
12933    (clobber (reg:CC FLAGS_REG))]
12934   ""
12935   "bsr{w}\t{%1, %0|%0, %1}"
12936   [(set_attr "type" "alu1")
12937    (set_attr "prefix_0f" "1")
12938    (set_attr "mode" "HI")])
12939
12940 (define_expand "popcount<mode>2"
12941   [(parallel
12942     [(set (match_operand:SWI248 0 "register_operand")
12943           (popcount:SWI248
12944             (match_operand:SWI248 1 "nonimmediate_operand")))
12945      (clobber (reg:CC FLAGS_REG))])]
12946   "TARGET_POPCNT")
12947
12948 (define_insn_and_split "*popcount<mode>2_falsedep_1"
12949   [(set (match_operand:SWI48 0 "register_operand" "=r")
12950         (popcount:SWI48
12951           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12952    (clobber (reg:CC FLAGS_REG))]
12953   "TARGET_POPCNT
12954    && TARGET_AVOID_FALSE_DEP_FOR_BMI && optimize_function_for_speed_p (cfun)"
12955   "#"
12956   "&& reload_completed"
12957   [(parallel
12958     [(set (match_dup 0)
12959           (popcount:SWI48 (match_dup 1)))
12960      (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)
12961      (clobber (reg:CC FLAGS_REG))])]
12962 {
12963   if (!reg_mentioned_p (operands[0], operands[1]))
12964     ix86_expand_clear (operands[0]);
12965 })
12966
12967 (define_insn "*popcount<mode>2_falsedep"
12968   [(set (match_operand:SWI48 0 "register_operand" "=r")
12969         (popcount:SWI48
12970           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12971    (unspec [(match_operand:SWI48 2 "register_operand" "0")]
12972            UNSPEC_INSN_FALSE_DEP)
12973    (clobber (reg:CC FLAGS_REG))]
12974   "TARGET_POPCNT"
12975 {
12976 #if TARGET_MACHO
12977   return "popcnt\t{%1, %0|%0, %1}";
12978 #else
12979   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12980 #endif
12981 }
12982   [(set_attr "prefix_rep" "1")
12983    (set_attr "type" "bitmanip")
12984    (set_attr "mode" "<MODE>")])
12985
12986 (define_insn "*popcount<mode>2"
12987   [(set (match_operand:SWI248 0 "register_operand" "=r")
12988         (popcount:SWI248
12989           (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12990    (clobber (reg:CC FLAGS_REG))]
12991   "TARGET_POPCNT"
12992 {
12993 #if TARGET_MACHO
12994   return "popcnt\t{%1, %0|%0, %1}";
12995 #else
12996   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12997 #endif
12998 }
12999   [(set_attr "prefix_rep" "1")
13000    (set_attr "type" "bitmanip")
13001    (set_attr "mode" "<MODE>")])
13002
13003 (define_expand "bswapdi2"
13004   [(set (match_operand:DI 0 "register_operand")
13005         (bswap:DI (match_operand:DI 1 "nonimmediate_operand")))]
13006   "TARGET_64BIT"
13007 {
13008   if (!TARGET_MOVBE)
13009     operands[1] = force_reg (DImode, operands[1]);
13010 })
13011
13012 (define_expand "bswapsi2"
13013   [(set (match_operand:SI 0 "register_operand")
13014         (bswap:SI (match_operand:SI 1 "nonimmediate_operand")))]
13015   ""
13016 {
13017   if (TARGET_MOVBE)
13018     ;
13019   else if (TARGET_BSWAP)
13020     operands[1] = force_reg (SImode, operands[1]);
13021   else
13022     {
13023       rtx x = operands[0];
13024
13025       emit_move_insn (x, operands[1]);
13026       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
13027       emit_insn (gen_rotlsi3 (x, x, GEN_INT (16)));
13028       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
13029       DONE;
13030     }
13031 })
13032
13033 (define_insn "*bswap<mode>2_movbe"
13034   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,r,m")
13035         (bswap:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,m,r")))]
13036   "TARGET_MOVBE
13037    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
13038   "@
13039     bswap\t%0
13040     movbe\t{%1, %0|%0, %1}
13041     movbe\t{%1, %0|%0, %1}"
13042   [(set_attr "type" "bitmanip,imov,imov")
13043    (set_attr "modrm" "0,1,1")
13044    (set_attr "prefix_0f" "*,1,1")
13045    (set_attr "prefix_extra" "*,1,1")
13046    (set_attr "mode" "<MODE>")])
13047
13048 (define_insn "*bswap<mode>2"
13049   [(set (match_operand:SWI48 0 "register_operand" "=r")
13050         (bswap:SWI48 (match_operand:SWI48 1 "register_operand" "0")))]
13051   "TARGET_BSWAP"
13052   "bswap\t%0"
13053   [(set_attr "type" "bitmanip")
13054    (set_attr "modrm" "0")
13055    (set_attr "mode" "<MODE>")])
13056
13057 (define_insn "*bswaphi_lowpart_1"
13058   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+Q,r"))
13059         (bswap:HI (match_dup 0)))
13060    (clobber (reg:CC FLAGS_REG))]
13061   "TARGET_USE_XCHGB || optimize_function_for_size_p (cfun)"
13062   "@
13063     xchg{b}\t{%h0, %b0|%b0, %h0}
13064     rol{w}\t{$8, %0|%0, 8}"
13065   [(set_attr "length" "2,4")
13066    (set_attr "mode" "QI,HI")])
13067
13068 (define_insn "bswaphi_lowpart"
13069   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
13070         (bswap:HI (match_dup 0)))
13071    (clobber (reg:CC FLAGS_REG))]
13072   ""
13073   "rol{w}\t{$8, %0|%0, 8}"
13074   [(set_attr "length" "4")
13075    (set_attr "mode" "HI")])
13076
13077 (define_expand "paritydi2"
13078   [(set (match_operand:DI 0 "register_operand")
13079         (parity:DI (match_operand:DI 1 "register_operand")))]
13080   "! TARGET_POPCNT"
13081 {
13082   rtx scratch = gen_reg_rtx (QImode);
13083   rtx cond;
13084
13085   emit_insn (gen_paritydi2_cmp (NULL_RTX, NULL_RTX,
13086                                 NULL_RTX, operands[1]));
13087
13088   cond = gen_rtx_fmt_ee (ORDERED, QImode,
13089                          gen_rtx_REG (CCmode, FLAGS_REG),
13090                          const0_rtx);
13091   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
13092
13093   if (TARGET_64BIT)
13094     emit_insn (gen_zero_extendqidi2 (operands[0], scratch));
13095   else
13096     {
13097       rtx tmp = gen_reg_rtx (SImode);
13098
13099       emit_insn (gen_zero_extendqisi2 (tmp, scratch));
13100       emit_insn (gen_zero_extendsidi2 (operands[0], tmp));
13101     }
13102   DONE;
13103 })
13104
13105 (define_expand "paritysi2"
13106   [(set (match_operand:SI 0 "register_operand")
13107         (parity:SI (match_operand:SI 1 "register_operand")))]
13108   "! TARGET_POPCNT"
13109 {
13110   rtx scratch = gen_reg_rtx (QImode);
13111   rtx cond;
13112
13113   emit_insn (gen_paritysi2_cmp (NULL_RTX, NULL_RTX, operands[1]));
13114
13115   cond = gen_rtx_fmt_ee (ORDERED, QImode,
13116                          gen_rtx_REG (CCmode, FLAGS_REG),
13117                          const0_rtx);
13118   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
13119
13120   emit_insn (gen_zero_extendqisi2 (operands[0], scratch));
13121   DONE;
13122 })
13123
13124 (define_insn_and_split "paritydi2_cmp"
13125   [(set (reg:CC FLAGS_REG)
13126         (unspec:CC [(match_operand:DI 3 "register_operand" "0")]
13127                    UNSPEC_PARITY))
13128    (clobber (match_scratch:DI 0 "=r"))
13129    (clobber (match_scratch:SI 1 "=&r"))
13130    (clobber (match_scratch:HI 2 "=Q"))]
13131   "! TARGET_POPCNT"
13132   "#"
13133   "&& reload_completed"
13134   [(parallel
13135      [(set (match_dup 1)
13136            (xor:SI (match_dup 1) (match_dup 4)))
13137       (clobber (reg:CC FLAGS_REG))])
13138    (parallel
13139      [(set (reg:CC FLAGS_REG)
13140            (unspec:CC [(match_dup 1)] UNSPEC_PARITY))
13141       (clobber (match_dup 1))
13142       (clobber (match_dup 2))])]
13143 {
13144   operands[4] = gen_lowpart (SImode, operands[3]);
13145
13146   if (TARGET_64BIT)
13147     {
13148       emit_move_insn (operands[1], gen_lowpart (SImode, operands[3]));
13149       emit_insn (gen_lshrdi3 (operands[3], operands[3], GEN_INT (32)));
13150     }
13151   else
13152     operands[1] = gen_highpart (SImode, operands[3]);
13153 })
13154
13155 (define_insn_and_split "paritysi2_cmp"
13156   [(set (reg:CC FLAGS_REG)
13157         (unspec:CC [(match_operand:SI 2 "register_operand" "0")]
13158                    UNSPEC_PARITY))
13159    (clobber (match_scratch:SI 0 "=r"))
13160    (clobber (match_scratch:HI 1 "=&Q"))]
13161   "! TARGET_POPCNT"
13162   "#"
13163   "&& reload_completed"
13164   [(parallel
13165      [(set (match_dup 1)
13166            (xor:HI (match_dup 1) (match_dup 3)))
13167       (clobber (reg:CC FLAGS_REG))])
13168    (parallel
13169      [(set (reg:CC FLAGS_REG)
13170            (unspec:CC [(match_dup 1)] UNSPEC_PARITY))
13171       (clobber (match_dup 1))])]
13172 {
13173   operands[3] = gen_lowpart (HImode, operands[2]);
13174
13175   emit_move_insn (operands[1], gen_lowpart (HImode, operands[2]));
13176   emit_insn (gen_lshrsi3 (operands[2], operands[2], GEN_INT (16)));
13177 })
13178
13179 (define_insn "*parityhi2_cmp"
13180   [(set (reg:CC FLAGS_REG)
13181         (unspec:CC [(match_operand:HI 1 "register_operand" "0")]
13182                    UNSPEC_PARITY))
13183    (clobber (match_scratch:HI 0 "=Q"))]
13184   "! TARGET_POPCNT"
13185   "xor{b}\t{%h0, %b0|%b0, %h0}"
13186   [(set_attr "length" "2")
13187    (set_attr "mode" "HI")])
13188
13189 \f
13190 ;; Thread-local storage patterns for ELF.
13191 ;;
13192 ;; Note that these code sequences must appear exactly as shown
13193 ;; in order to allow linker relaxation.
13194
13195 (define_insn "*tls_global_dynamic_32_gnu"
13196   [(set (match_operand:SI 0 "register_operand" "=a")
13197         (unspec:SI
13198          [(match_operand:SI 1 "register_operand" "b")
13199           (match_operand 2 "tls_symbolic_operand")
13200           (match_operand 3 "constant_call_address_operand" "Bz")
13201           (reg:SI SP_REG)]
13202          UNSPEC_TLS_GD))
13203    (clobber (match_scratch:SI 4 "=d"))
13204    (clobber (match_scratch:SI 5 "=c"))
13205    (clobber (reg:CC FLAGS_REG))]
13206   "!TARGET_64BIT && TARGET_GNU_TLS"
13207 {
13208   output_asm_insn
13209     ("lea{l}\t{%E2@tlsgd(,%1,1), %0|%0, %E2@tlsgd[%1*1]}", operands);
13210   if (TARGET_SUN_TLS)
13211 #ifdef HAVE_AS_IX86_TLSGDPLT
13212     return "call\t%a2@tlsgdplt";
13213 #else
13214     return "call\t%p3@plt";
13215 #endif
13216   return "call\t%P3";
13217 }
13218   [(set_attr "type" "multi")
13219    (set_attr "length" "12")])
13220
13221 (define_expand "tls_global_dynamic_32"
13222   [(parallel
13223     [(set (match_operand:SI 0 "register_operand")
13224           (unspec:SI [(match_operand:SI 2 "register_operand")
13225                       (match_operand 1 "tls_symbolic_operand")
13226                       (match_operand 3 "constant_call_address_operand")
13227                       (reg:SI SP_REG)]
13228                      UNSPEC_TLS_GD))
13229      (clobber (match_scratch:SI 4))
13230      (clobber (match_scratch:SI 5))
13231      (clobber (reg:CC FLAGS_REG))])]
13232   ""
13233   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13234
13235 (define_insn "*tls_global_dynamic_64_<mode>"
13236   [(set (match_operand:P 0 "register_operand" "=a")
13237         (call:P
13238          (mem:QI (match_operand 2 "constant_call_address_operand" "Bz"))
13239          (match_operand 3)))
13240    (unspec:P [(match_operand 1 "tls_symbolic_operand")]
13241              UNSPEC_TLS_GD)]
13242   "TARGET_64BIT"
13243 {
13244   if (!TARGET_X32)
13245     fputs (ASM_BYTE "0x66\n", asm_out_file);
13246   output_asm_insn
13247     ("lea{q}\t{%E1@tlsgd(%%rip), %%rdi|rdi, %E1@tlsgd[rip]}", operands);
13248   fputs (ASM_SHORT "0x6666\n", asm_out_file);
13249   fputs ("\trex64\n", asm_out_file);
13250   if (TARGET_SUN_TLS)
13251     return "call\t%p2@plt";
13252   return "call\t%P2";
13253 }
13254   [(set_attr "type" "multi")
13255    (set (attr "length")
13256         (symbol_ref "TARGET_X32 ? 15 : 16"))])
13257
13258 (define_insn "*tls_global_dynamic_64_largepic"
13259   [(set (match_operand:DI 0 "register_operand" "=a")
13260         (call:DI
13261          (mem:QI (plus:DI (match_operand:DI 2 "register_operand" "b")
13262                           (match_operand:DI 3 "immediate_operand" "i")))
13263          (match_operand 4)))
13264    (unspec:DI [(match_operand 1 "tls_symbolic_operand")]
13265              UNSPEC_TLS_GD)]
13266   "TARGET_64BIT && ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF
13267    && GET_CODE (operands[3]) == CONST
13268    && GET_CODE (XEXP (operands[3], 0)) == UNSPEC
13269    && XINT (XEXP (operands[3], 0), 1) == UNSPEC_PLTOFF"
13270 {
13271   output_asm_insn
13272     ("lea{q}\t{%E1@tlsgd(%%rip), %%rdi|rdi, %E1@tlsgd[rip]}", operands);
13273   output_asm_insn ("movabs{q}\t{%3, %%rax|rax, %3}", operands);
13274   output_asm_insn ("add{q}\t{%2, %%rax|rax, %2}", operands);
13275   return "call\t{*%%rax|rax}";
13276 }
13277   [(set_attr "type" "multi")
13278    (set_attr "length" "22")])
13279
13280 (define_expand "tls_global_dynamic_64_<mode>"
13281   [(parallel
13282     [(set (match_operand:P 0 "register_operand")
13283           (call:P
13284            (mem:QI (match_operand 2))
13285            (const_int 0)))
13286      (unspec:P [(match_operand 1 "tls_symbolic_operand")]
13287                UNSPEC_TLS_GD)])]
13288   "TARGET_64BIT"
13289   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13290
13291 (define_insn "*tls_local_dynamic_base_32_gnu"
13292   [(set (match_operand:SI 0 "register_operand" "=a")
13293         (unspec:SI
13294          [(match_operand:SI 1 "register_operand" "b")
13295           (match_operand 2 "constant_call_address_operand" "Bz")
13296           (reg:SI SP_REG)]
13297          UNSPEC_TLS_LD_BASE))
13298    (clobber (match_scratch:SI 3 "=d"))
13299    (clobber (match_scratch:SI 4 "=c"))
13300    (clobber (reg:CC FLAGS_REG))]
13301   "!TARGET_64BIT && TARGET_GNU_TLS"
13302 {
13303   output_asm_insn
13304     ("lea{l}\t{%&@tlsldm(%1), %0|%0, %&@tlsldm[%1]}", operands);
13305   if (TARGET_SUN_TLS)
13306     {
13307       if (HAVE_AS_IX86_TLSLDMPLT)
13308         return "call\t%&@tlsldmplt";
13309       else
13310         return "call\t%p2@plt";
13311     }
13312   return "call\t%P2";
13313 }
13314   [(set_attr "type" "multi")
13315    (set_attr "length" "11")])
13316
13317 (define_expand "tls_local_dynamic_base_32"
13318   [(parallel
13319      [(set (match_operand:SI 0 "register_operand")
13320            (unspec:SI
13321             [(match_operand:SI 1 "register_operand")
13322              (match_operand 2 "constant_call_address_operand")
13323              (reg:SI SP_REG)]
13324             UNSPEC_TLS_LD_BASE))
13325       (clobber (match_scratch:SI 3))
13326       (clobber (match_scratch:SI 4))
13327       (clobber (reg:CC FLAGS_REG))])]
13328   ""
13329   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13330
13331 (define_insn "*tls_local_dynamic_base_64_<mode>"
13332   [(set (match_operand:P 0 "register_operand" "=a")
13333         (call:P
13334          (mem:QI (match_operand 1 "constant_call_address_operand" "Bz"))
13335          (match_operand 2)))
13336    (unspec:P [(const_int 0)] UNSPEC_TLS_LD_BASE)]
13337   "TARGET_64BIT"
13338 {
13339   output_asm_insn
13340     ("lea{q}\t{%&@tlsld(%%rip), %%rdi|rdi, %&@tlsld[rip]}", operands);
13341   if (TARGET_SUN_TLS)
13342     return "call\t%p1@plt";
13343   return "call\t%P1";
13344 }
13345   [(set_attr "type" "multi")
13346    (set_attr "length" "12")])
13347
13348 (define_insn "*tls_local_dynamic_base_64_largepic"
13349   [(set (match_operand:DI 0 "register_operand" "=a")
13350         (call:DI
13351          (mem:QI (plus:DI (match_operand:DI 1 "register_operand" "b")
13352                           (match_operand:DI 2 "immediate_operand" "i")))
13353          (match_operand 3)))
13354    (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)]
13355   "TARGET_64BIT && ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF
13356    && GET_CODE (operands[2]) == CONST
13357    && GET_CODE (XEXP (operands[2], 0)) == UNSPEC
13358    && XINT (XEXP (operands[2], 0), 1) == UNSPEC_PLTOFF"
13359 {
13360   output_asm_insn
13361     ("lea{q}\t{%&@tlsld(%%rip), %%rdi|rdi, %&@tlsld[rip]}", operands);
13362   output_asm_insn ("movabs{q}\t{%2, %%rax|rax, %2}", operands);
13363   output_asm_insn ("add{q}\t{%1, %%rax|rax, %1}", operands);
13364   return "call\t{*%%rax|rax}";
13365 }
13366   [(set_attr "type" "multi")
13367    (set_attr "length" "22")])
13368
13369 (define_expand "tls_local_dynamic_base_64_<mode>"
13370   [(parallel
13371      [(set (match_operand:P 0 "register_operand")
13372            (call:P
13373             (mem:QI (match_operand 1))
13374             (const_int 0)))
13375       (unspec:P [(const_int 0)] UNSPEC_TLS_LD_BASE)])]
13376   "TARGET_64BIT"
13377   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13378
13379 ;; Local dynamic of a single variable is a lose.  Show combine how
13380 ;; to convert that back to global dynamic.
13381
13382 (define_insn_and_split "*tls_local_dynamic_32_once"
13383   [(set (match_operand:SI 0 "register_operand" "=a")
13384         (plus:SI
13385          (unspec:SI [(match_operand:SI 1 "register_operand" "b")
13386                      (match_operand 2 "constant_call_address_operand" "Bz")
13387                      (reg:SI SP_REG)]
13388                     UNSPEC_TLS_LD_BASE)
13389          (const:SI (unspec:SI
13390                     [(match_operand 3 "tls_symbolic_operand")]
13391                     UNSPEC_DTPOFF))))
13392    (clobber (match_scratch:SI 4 "=d"))
13393    (clobber (match_scratch:SI 5 "=c"))
13394    (clobber (reg:CC FLAGS_REG))]
13395   ""
13396   "#"
13397   ""
13398   [(parallel
13399      [(set (match_dup 0)
13400            (unspec:SI [(match_dup 1) (match_dup 3) (match_dup 2)
13401                        (reg:SI SP_REG)]
13402                       UNSPEC_TLS_GD))
13403       (clobber (match_dup 4))
13404       (clobber (match_dup 5))
13405       (clobber (reg:CC FLAGS_REG))])])
13406
13407 ;; Segment register for the thread base ptr load
13408 (define_mode_attr tp_seg [(SI "gs") (DI "fs")])
13409
13410 ;; Load and add the thread base pointer from %<tp_seg>:0.
13411 (define_insn "*load_tp_x32"
13412   [(set (match_operand:SI 0 "register_operand" "=r")
13413         (unspec:SI [(const_int 0)] UNSPEC_TP))]
13414   "TARGET_X32"
13415   "mov{l}\t{%%fs:0, %0|%0, DWORD PTR fs:0}"
13416   [(set_attr "type" "imov")
13417    (set_attr "modrm" "0")
13418    (set_attr "length" "7")
13419    (set_attr "memory" "load")
13420    (set_attr "imm_disp" "false")])
13421
13422 (define_insn "*load_tp_x32_zext"
13423   [(set (match_operand:DI 0 "register_operand" "=r")
13424         (zero_extend:DI (unspec:SI [(const_int 0)] UNSPEC_TP)))]
13425   "TARGET_X32"
13426   "mov{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"
13427   [(set_attr "type" "imov")
13428    (set_attr "modrm" "0")
13429    (set_attr "length" "7")
13430    (set_attr "memory" "load")
13431    (set_attr "imm_disp" "false")])
13432
13433 (define_insn "*load_tp_<mode>"
13434   [(set (match_operand:P 0 "register_operand" "=r")
13435         (unspec:P [(const_int 0)] UNSPEC_TP))]
13436   "!TARGET_X32"
13437   "mov{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
13438   [(set_attr "type" "imov")
13439    (set_attr "modrm" "0")
13440    (set_attr "length" "7")
13441    (set_attr "memory" "load")
13442    (set_attr "imm_disp" "false")])
13443
13444 (define_insn "*add_tp_x32"
13445   [(set (match_operand:SI 0 "register_operand" "=r")
13446         (plus:SI (unspec:SI [(const_int 0)] UNSPEC_TP)
13447                  (match_operand:SI 1 "register_operand" "0")))
13448    (clobber (reg:CC FLAGS_REG))]
13449   "TARGET_X32"
13450   "add{l}\t{%%fs:0, %0|%0, DWORD PTR fs:0}"
13451   [(set_attr "type" "alu")
13452    (set_attr "modrm" "0")
13453    (set_attr "length" "7")
13454    (set_attr "memory" "load")
13455    (set_attr "imm_disp" "false")])
13456
13457 (define_insn "*add_tp_x32_zext"
13458   [(set (match_operand:DI 0 "register_operand" "=r")
13459         (zero_extend:DI
13460           (plus:SI (unspec:SI [(const_int 0)] UNSPEC_TP)
13461                    (match_operand:SI 1 "register_operand" "0"))))
13462    (clobber (reg:CC FLAGS_REG))]
13463   "TARGET_X32"
13464   "add{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"
13465   [(set_attr "type" "alu")
13466    (set_attr "modrm" "0")
13467    (set_attr "length" "7")
13468    (set_attr "memory" "load")
13469    (set_attr "imm_disp" "false")])
13470
13471 (define_insn "*add_tp_<mode>"
13472   [(set (match_operand:P 0 "register_operand" "=r")
13473         (plus:P (unspec:P [(const_int 0)] UNSPEC_TP)
13474                 (match_operand:P 1 "register_operand" "0")))
13475    (clobber (reg:CC FLAGS_REG))]
13476   "!TARGET_X32"
13477   "add{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
13478   [(set_attr "type" "alu")
13479    (set_attr "modrm" "0")
13480    (set_attr "length" "7")
13481    (set_attr "memory" "load")
13482    (set_attr "imm_disp" "false")])
13483
13484 ;; The Sun linker took the AMD64 TLS spec literally and can only handle
13485 ;; %rax as destination of the initial executable code sequence.
13486 (define_insn "tls_initial_exec_64_sun"
13487   [(set (match_operand:DI 0 "register_operand" "=a")
13488         (unspec:DI
13489          [(match_operand 1 "tls_symbolic_operand")]
13490          UNSPEC_TLS_IE_SUN))
13491    (clobber (reg:CC FLAGS_REG))]
13492   "TARGET_64BIT && TARGET_SUN_TLS"
13493 {
13494   output_asm_insn
13495     ("mov{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}", operands);
13496   return "add{q}\t{%a1@gottpoff(%%rip), %0|%0, %a1@gottpoff[rip]}";
13497 }
13498   [(set_attr "type" "multi")])
13499
13500 ;; GNU2 TLS patterns can be split.
13501
13502 (define_expand "tls_dynamic_gnu2_32"
13503   [(set (match_dup 3)
13504         (plus:SI (match_operand:SI 2 "register_operand")
13505                  (const:SI
13506                   (unspec:SI [(match_operand 1 "tls_symbolic_operand")]
13507                              UNSPEC_TLSDESC))))
13508    (parallel
13509     [(set (match_operand:SI 0 "register_operand")
13510           (unspec:SI [(match_dup 1) (match_dup 3)
13511                       (match_dup 2) (reg:SI SP_REG)]
13512                       UNSPEC_TLSDESC))
13513      (clobber (reg:CC FLAGS_REG))])]
13514   "!TARGET_64BIT && TARGET_GNU2_TLS"
13515 {
13516   operands[3] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13517   ix86_tls_descriptor_calls_expanded_in_cfun = true;
13518 })
13519
13520 (define_insn "*tls_dynamic_gnu2_lea_32"
13521   [(set (match_operand:SI 0 "register_operand" "=r")
13522         (plus:SI (match_operand:SI 1 "register_operand" "b")
13523                  (const:SI
13524                   (unspec:SI [(match_operand 2 "tls_symbolic_operand")]
13525                               UNSPEC_TLSDESC))))]
13526   "!TARGET_64BIT && TARGET_GNU2_TLS"
13527   "lea{l}\t{%E2@TLSDESC(%1), %0|%0, %E2@TLSDESC[%1]}"
13528   [(set_attr "type" "lea")
13529    (set_attr "mode" "SI")
13530    (set_attr "length" "6")
13531    (set_attr "length_address" "4")])
13532
13533 (define_insn "*tls_dynamic_gnu2_call_32"
13534   [(set (match_operand:SI 0 "register_operand" "=a")
13535         (unspec:SI [(match_operand 1 "tls_symbolic_operand")
13536                     (match_operand:SI 2 "register_operand" "0")
13537                     ;; we have to make sure %ebx still points to the GOT
13538                     (match_operand:SI 3 "register_operand" "b")
13539                     (reg:SI SP_REG)]
13540                    UNSPEC_TLSDESC))
13541    (clobber (reg:CC FLAGS_REG))]
13542   "!TARGET_64BIT && TARGET_GNU2_TLS"
13543   "call\t{*%a1@TLSCALL(%2)|[DWORD PTR [%2+%a1@TLSCALL]]}"
13544   [(set_attr "type" "call")
13545    (set_attr "length" "2")
13546    (set_attr "length_address" "0")])
13547
13548 (define_insn_and_split "*tls_dynamic_gnu2_combine_32"
13549   [(set (match_operand:SI 0 "register_operand" "=&a")
13550         (plus:SI
13551          (unspec:SI [(match_operand 3 "tls_modbase_operand")
13552                      (match_operand:SI 4)
13553                      (match_operand:SI 2 "register_operand" "b")
13554                      (reg:SI SP_REG)]
13555                     UNSPEC_TLSDESC)
13556          (const:SI (unspec:SI
13557                     [(match_operand 1 "tls_symbolic_operand")]
13558                     UNSPEC_DTPOFF))))
13559    (clobber (reg:CC FLAGS_REG))]
13560   "!TARGET_64BIT && TARGET_GNU2_TLS"
13561   "#"
13562   ""
13563   [(set (match_dup 0) (match_dup 5))]
13564 {
13565   operands[5] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13566   emit_insn (gen_tls_dynamic_gnu2_32 (operands[5], operands[1], operands[2]));
13567 })
13568
13569 (define_expand "tls_dynamic_gnu2_64"
13570   [(set (match_dup 2)
13571         (unspec:DI [(match_operand 1 "tls_symbolic_operand")]
13572                    UNSPEC_TLSDESC))
13573    (parallel
13574     [(set (match_operand:DI 0 "register_operand")
13575           (unspec:DI [(match_dup 1) (match_dup 2) (reg:DI SP_REG)]
13576                      UNSPEC_TLSDESC))
13577      (clobber (reg:CC FLAGS_REG))])]
13578   "TARGET_64BIT && TARGET_GNU2_TLS"
13579 {
13580   operands[2] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13581   ix86_tls_descriptor_calls_expanded_in_cfun = true;
13582 })
13583
13584 (define_insn "*tls_dynamic_gnu2_lea_64"
13585   [(set (match_operand:DI 0 "register_operand" "=r")
13586         (unspec:DI [(match_operand 1 "tls_symbolic_operand")]
13587                    UNSPEC_TLSDESC))]
13588   "TARGET_64BIT && TARGET_GNU2_TLS"
13589   "lea{q}\t{%E1@TLSDESC(%%rip), %0|%0, %E1@TLSDESC[rip]}"
13590   [(set_attr "type" "lea")
13591    (set_attr "mode" "DI")
13592    (set_attr "length" "7")
13593    (set_attr "length_address" "4")])
13594
13595 (define_insn "*tls_dynamic_gnu2_call_64"
13596   [(set (match_operand:DI 0 "register_operand" "=a")
13597         (unspec:DI [(match_operand 1 "tls_symbolic_operand")
13598                     (match_operand:DI 2 "register_operand" "0")
13599                     (reg:DI SP_REG)]
13600                    UNSPEC_TLSDESC))
13601    (clobber (reg:CC FLAGS_REG))]
13602   "TARGET_64BIT && TARGET_GNU2_TLS"
13603   "call\t{*%a1@TLSCALL(%2)|[QWORD PTR [%2+%a1@TLSCALL]]}"
13604   [(set_attr "type" "call")
13605    (set_attr "length" "2")
13606    (set_attr "length_address" "0")])
13607
13608 (define_insn_and_split "*tls_dynamic_gnu2_combine_64"
13609   [(set (match_operand:DI 0 "register_operand" "=&a")
13610         (plus:DI
13611          (unspec:DI [(match_operand 2 "tls_modbase_operand")
13612                      (match_operand:DI 3)
13613                      (reg:DI SP_REG)]
13614                     UNSPEC_TLSDESC)
13615          (const:DI (unspec:DI
13616                     [(match_operand 1 "tls_symbolic_operand")]
13617                     UNSPEC_DTPOFF))))
13618    (clobber (reg:CC FLAGS_REG))]
13619   "TARGET_64BIT && TARGET_GNU2_TLS"
13620   "#"
13621   ""
13622   [(set (match_dup 0) (match_dup 4))]
13623 {
13624   operands[4] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13625   emit_insn (gen_tls_dynamic_gnu2_64 (operands[4], operands[1]));
13626 })
13627 \f
13628 ;; These patterns match the binary 387 instructions for addM3, subM3,
13629 ;; mulM3 and divM3.  There are three patterns for each of DFmode and
13630 ;; SFmode.  The first is the normal insn, the second the same insn but
13631 ;; with one operand a conversion, and the third the same insn but with
13632 ;; the other operand a conversion.  The conversion may be SFmode or
13633 ;; SImode if the target mode DFmode, but only SImode if the target mode
13634 ;; is SFmode.
13635
13636 ;; Gcc is slightly more smart about handling normal two address instructions
13637 ;; so use special patterns for add and mull.
13638
13639 (define_insn "*fop_<mode>_comm_mixed"
13640   [(set (match_operand:MODEF 0 "register_operand" "=f,x,x")
13641         (match_operator:MODEF 3 "binary_fp_operator"
13642           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,0,x")
13643            (match_operand:MODEF 2 "nonimmediate_operand" "fm,xm,xm")]))]
13644   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
13645    && COMMUTATIVE_ARITH_P (operands[3])
13646    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13647   "* return output_387_binary_op (insn, operands);"
13648   [(set (attr "type")
13649         (if_then_else (eq_attr "alternative" "1,2")
13650            (if_then_else (match_operand:MODEF 3 "mult_operator")
13651               (const_string "ssemul")
13652               (const_string "sseadd"))
13653            (if_then_else (match_operand:MODEF 3 "mult_operator")
13654               (const_string "fmul")
13655               (const_string "fop"))))
13656    (set_attr "isa" "*,noavx,avx")
13657    (set_attr "prefix" "orig,orig,vex")
13658    (set_attr "mode" "<MODE>")])
13659
13660 (define_insn "*fop_<mode>_comm_sse"
13661   [(set (match_operand:MODEF 0 "register_operand" "=x,v")
13662         (match_operator:MODEF 3 "binary_fp_operator"
13663           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,v")
13664            (match_operand:MODEF 2 "nonimmediate_operand" "xm,vm")]))]
13665   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
13666    && COMMUTATIVE_ARITH_P (operands[3])
13667    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13668   "* return output_387_binary_op (insn, operands);"
13669   [(set (attr "type")
13670         (if_then_else (match_operand:MODEF 3 "mult_operator")
13671            (const_string "ssemul")
13672            (const_string "sseadd")))
13673    (set_attr "isa" "noavx,avx")
13674    (set_attr "prefix" "orig,vex")
13675    (set_attr "mode" "<MODE>")])
13676
13677 (define_insn "*fop_<mode>_comm_i387"
13678   [(set (match_operand:MODEF 0 "register_operand" "=f")
13679         (match_operator:MODEF 3 "binary_fp_operator"
13680           [(match_operand:MODEF 1 "nonimmediate_operand" "%0")
13681            (match_operand:MODEF 2 "nonimmediate_operand" "fm")]))]
13682   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
13683    && COMMUTATIVE_ARITH_P (operands[3])
13684    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13685   "* return output_387_binary_op (insn, operands);"
13686   [(set (attr "type")
13687         (if_then_else (match_operand:MODEF 3 "mult_operator")
13688            (const_string "fmul")
13689            (const_string "fop")))
13690    (set_attr "mode" "<MODE>")])
13691
13692 (define_insn "*fop_<mode>_1_mixed"
13693   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x,x")
13694         (match_operator:MODEF 3 "binary_fp_operator"
13695           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm,0,x")
13696            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0,xm,xm")]))]
13697   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
13698    && !COMMUTATIVE_ARITH_P (operands[3])
13699    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13700   "* return output_387_binary_op (insn, operands);"
13701   [(set (attr "type")
13702         (cond [(and (eq_attr "alternative" "2,3")
13703                     (match_operand:MODEF 3 "mult_operator"))
13704                  (const_string "ssemul")
13705                (and (eq_attr "alternative" "2,3")
13706                     (match_operand:MODEF 3 "div_operator"))
13707                  (const_string "ssediv")
13708                (eq_attr "alternative" "2,3")
13709                  (const_string "sseadd")
13710                (match_operand:MODEF 3 "mult_operator")
13711                  (const_string "fmul")
13712                (match_operand:MODEF 3 "div_operator")
13713                  (const_string "fdiv")
13714               ]
13715               (const_string "fop")))
13716    (set_attr "isa" "*,*,noavx,avx")
13717    (set_attr "prefix" "orig,orig,orig,vex")
13718    (set_attr "mode" "<MODE>")])
13719
13720 (define_insn "*rcpsf2_sse"
13721   [(set (match_operand:SF 0 "register_operand" "=x")
13722         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
13723                    UNSPEC_RCP))]
13724   "TARGET_SSE_MATH"
13725   "%vrcpss\t{%1, %d0|%d0, %1}"
13726   [(set_attr "type" "sse")
13727    (set_attr "atom_sse_attr" "rcp")
13728    (set_attr "btver2_sse_attr" "rcp")
13729    (set_attr "prefix" "maybe_vex")
13730    (set_attr "mode" "SF")])
13731
13732 (define_insn "*fop_<mode>_1_sse"
13733   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
13734         (match_operator:MODEF 3 "binary_fp_operator"
13735           [(match_operand:MODEF 1 "register_operand" "0,x")
13736            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]))]
13737   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
13738    && !COMMUTATIVE_ARITH_P (operands[3])"
13739   "* return output_387_binary_op (insn, operands);"
13740   [(set (attr "type")
13741         (cond [(match_operand:MODEF 3 "mult_operator")
13742                  (const_string "ssemul")
13743                (match_operand:MODEF 3 "div_operator")
13744                  (const_string "ssediv")
13745               ]
13746               (const_string "sseadd")))
13747    (set_attr "isa" "noavx,avx")
13748    (set_attr "prefix" "orig,vex")
13749    (set_attr "mode" "<MODE>")])
13750
13751 ;; This pattern is not fully shadowed by the pattern above.
13752 (define_insn "*fop_<mode>_1_i387"
13753   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
13754         (match_operator:MODEF 3 "binary_fp_operator"
13755           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm")
13756            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0")]))]
13757   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
13758    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13759    && !COMMUTATIVE_ARITH_P (operands[3])
13760    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13761   "* return output_387_binary_op (insn, operands);"
13762   [(set (attr "type")
13763         (cond [(match_operand:MODEF 3 "mult_operator")
13764                  (const_string "fmul")
13765                (match_operand:MODEF 3 "div_operator")
13766                  (const_string "fdiv")
13767               ]
13768               (const_string "fop")))
13769    (set_attr "mode" "<MODE>")])
13770
13771 ;; ??? Add SSE splitters for these!
13772 (define_insn "*fop_<MODEF:mode>_2_i387"
13773   [(set (match_operand:MODEF 0 "register_operand" "=f")
13774         (match_operator:MODEF 3 "binary_fp_operator"
13775           [(float:MODEF
13776              (match_operand:SWI24 1 "nonimmediate_operand" "m"))
13777            (match_operand:MODEF 2 "register_operand" "0")]))]
13778   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI24:MODE>mode)
13779    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
13780    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
13781        || optimize_function_for_size_p (cfun))"
13782   { return output_387_binary_op (insn, operands); }
13783   [(set (attr "type")
13784         (cond [(match_operand:MODEF 3 "mult_operator")
13785                  (const_string "fmul")
13786                (match_operand:MODEF 3 "div_operator")
13787                  (const_string "fdiv")
13788               ]
13789               (const_string "fop")))
13790    (set_attr "fp_int_src" "true")
13791    (set_attr "mode" "<SWI24:MODE>")])
13792
13793 (define_insn "*fop_<MODEF:mode>_3_i387"
13794   [(set (match_operand:MODEF 0 "register_operand" "=f")
13795         (match_operator:MODEF 3 "binary_fp_operator"
13796           [(match_operand:MODEF 1 "register_operand" "0")
13797            (float:MODEF
13798              (match_operand:SWI24 2 "nonimmediate_operand" "m"))]))]
13799   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI24:MODE>mode)
13800    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
13801    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
13802        || optimize_function_for_size_p (cfun))"
13803   { return output_387_binary_op (insn, operands); }
13804   [(set (attr "type")
13805         (cond [(match_operand:MODEF 3 "mult_operator")
13806                  (const_string "fmul")
13807                (match_operand:MODEF 3 "div_operator")
13808                  (const_string "fdiv")
13809               ]
13810               (const_string "fop")))
13811    (set_attr "fp_int_src" "true")
13812    (set_attr "mode" "<MODE>")])
13813
13814 (define_insn "*fop_df_4_i387"
13815   [(set (match_operand:DF 0 "register_operand" "=f,f")
13816         (match_operator:DF 3 "binary_fp_operator"
13817            [(float_extend:DF
13818              (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
13819             (match_operand:DF 2 "register_operand" "0,f")]))]
13820   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13821    && !(TARGET_SSE2 && TARGET_SSE_MATH)
13822    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13823   "* return output_387_binary_op (insn, operands);"
13824   [(set (attr "type")
13825         (cond [(match_operand:DF 3 "mult_operator")
13826                  (const_string "fmul")
13827                (match_operand:DF 3 "div_operator")
13828                  (const_string "fdiv")
13829               ]
13830               (const_string "fop")))
13831    (set_attr "mode" "SF")])
13832
13833 (define_insn "*fop_df_5_i387"
13834   [(set (match_operand:DF 0 "register_operand" "=f,f")
13835         (match_operator:DF 3 "binary_fp_operator"
13836           [(match_operand:DF 1 "register_operand" "0,f")
13837            (float_extend:DF
13838             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
13839   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13840    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
13841   "* return output_387_binary_op (insn, operands);"
13842   [(set (attr "type")
13843         (cond [(match_operand:DF 3 "mult_operator")
13844                  (const_string "fmul")
13845                (match_operand:DF 3 "div_operator")
13846                  (const_string "fdiv")
13847               ]
13848               (const_string "fop")))
13849    (set_attr "mode" "SF")])
13850
13851 (define_insn "*fop_df_6_i387"
13852   [(set (match_operand:DF 0 "register_operand" "=f,f")
13853         (match_operator:DF 3 "binary_fp_operator"
13854           [(float_extend:DF
13855             (match_operand:SF 1 "register_operand" "0,f"))
13856            (float_extend:DF
13857             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
13858   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13859    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
13860   "* return output_387_binary_op (insn, operands);"
13861   [(set (attr "type")
13862         (cond [(match_operand:DF 3 "mult_operator")
13863                  (const_string "fmul")
13864                (match_operand:DF 3 "div_operator")
13865                  (const_string "fdiv")
13866               ]
13867               (const_string "fop")))
13868    (set_attr "mode" "SF")])
13869
13870 (define_insn "*fop_xf_comm_i387"
13871   [(set (match_operand:XF 0 "register_operand" "=f")
13872         (match_operator:XF 3 "binary_fp_operator"
13873                         [(match_operand:XF 1 "register_operand" "%0")
13874                          (match_operand:XF 2 "register_operand" "f")]))]
13875   "TARGET_80387
13876    && COMMUTATIVE_ARITH_P (operands[3])"
13877   "* return output_387_binary_op (insn, operands);"
13878   [(set (attr "type")
13879         (if_then_else (match_operand:XF 3 "mult_operator")
13880            (const_string "fmul")
13881            (const_string "fop")))
13882    (set_attr "mode" "XF")])
13883
13884 (define_insn "*fop_xf_1_i387"
13885   [(set (match_operand:XF 0 "register_operand" "=f,f")
13886         (match_operator:XF 3 "binary_fp_operator"
13887                         [(match_operand:XF 1 "register_operand" "0,f")
13888                          (match_operand:XF 2 "register_operand" "f,0")]))]
13889   "TARGET_80387
13890    && !COMMUTATIVE_ARITH_P (operands[3])"
13891   "* return output_387_binary_op (insn, operands);"
13892   [(set (attr "type")
13893         (cond [(match_operand:XF 3 "mult_operator")
13894                  (const_string "fmul")
13895                (match_operand:XF 3 "div_operator")
13896                  (const_string "fdiv")
13897               ]
13898               (const_string "fop")))
13899    (set_attr "mode" "XF")])
13900
13901 (define_insn "*fop_xf_2_i387"
13902   [(set (match_operand:XF 0 "register_operand" "=f")
13903         (match_operator:XF 3 "binary_fp_operator"
13904           [(float:XF
13905              (match_operand:SWI24 1 "nonimmediate_operand" "m"))
13906            (match_operand:XF 2 "register_operand" "0")]))]
13907   "TARGET_80387
13908    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
13909   { return output_387_binary_op (insn, operands); }
13910   [(set (attr "type")
13911         (cond [(match_operand:XF 3 "mult_operator")
13912                  (const_string "fmul")
13913                (match_operand:XF 3 "div_operator")
13914                  (const_string "fdiv")
13915               ]
13916               (const_string "fop")))
13917    (set_attr "fp_int_src" "true")
13918    (set_attr "mode" "<MODE>")])
13919
13920 (define_insn "*fop_xf_3_i387"
13921   [(set (match_operand:XF 0 "register_operand" "=f")
13922         (match_operator:XF 3 "binary_fp_operator"
13923           [(match_operand:XF 1 "register_operand" "0")
13924            (float:XF
13925              (match_operand:SWI24 2 "nonimmediate_operand" "m"))]))]
13926   "TARGET_80387
13927    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
13928   { return output_387_binary_op (insn, operands); }
13929   [(set (attr "type")
13930         (cond [(match_operand:XF 3 "mult_operator")
13931                  (const_string "fmul")
13932                (match_operand:XF 3 "div_operator")
13933                  (const_string "fdiv")
13934               ]
13935               (const_string "fop")))
13936    (set_attr "fp_int_src" "true")
13937    (set_attr "mode" "<MODE>")])
13938
13939 (define_insn "*fop_xf_4_i387"
13940   [(set (match_operand:XF 0 "register_operand" "=f,f")
13941         (match_operator:XF 3 "binary_fp_operator"
13942            [(float_extend:XF
13943               (match_operand:MODEF 1 "nonimmediate_operand" "fm,0"))
13944             (match_operand:XF 2 "register_operand" "0,f")]))]
13945   "TARGET_80387"
13946   "* return output_387_binary_op (insn, operands);"
13947   [(set (attr "type")
13948         (cond [(match_operand:XF 3 "mult_operator")
13949                  (const_string "fmul")
13950                (match_operand:XF 3 "div_operator")
13951                  (const_string "fdiv")
13952               ]
13953               (const_string "fop")))
13954    (set_attr "mode" "<MODE>")])
13955
13956 (define_insn "*fop_xf_5_i387"
13957   [(set (match_operand:XF 0 "register_operand" "=f,f")
13958         (match_operator:XF 3 "binary_fp_operator"
13959           [(match_operand:XF 1 "register_operand" "0,f")
13960            (float_extend:XF
13961              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
13962   "TARGET_80387"
13963   "* return output_387_binary_op (insn, operands);"
13964   [(set (attr "type")
13965         (cond [(match_operand:XF 3 "mult_operator")
13966                  (const_string "fmul")
13967                (match_operand:XF 3 "div_operator")
13968                  (const_string "fdiv")
13969               ]
13970               (const_string "fop")))
13971    (set_attr "mode" "<MODE>")])
13972
13973 (define_insn "*fop_xf_6_i387"
13974   [(set (match_operand:XF 0 "register_operand" "=f,f")
13975         (match_operator:XF 3 "binary_fp_operator"
13976           [(float_extend:XF
13977              (match_operand:MODEF 1 "register_operand" "0,f"))
13978            (float_extend:XF
13979              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
13980   "TARGET_80387"
13981   "* return output_387_binary_op (insn, operands);"
13982   [(set (attr "type")
13983         (cond [(match_operand:XF 3 "mult_operator")
13984                  (const_string "fmul")
13985                (match_operand:XF 3 "div_operator")
13986                  (const_string "fdiv")
13987               ]
13988               (const_string "fop")))
13989    (set_attr "mode" "<MODE>")])
13990 \f
13991 ;; FPU special functions.
13992
13993 ;; This pattern implements a no-op XFmode truncation for
13994 ;; all fancy i386 XFmode math functions.
13995
13996 (define_insn "truncxf<mode>2_i387_noop_unspec"
13997   [(set (match_operand:MODEF 0 "register_operand" "=f")
13998         (unspec:MODEF [(match_operand:XF 1 "register_operand" "f")]
13999         UNSPEC_TRUNC_NOOP))]
14000   "TARGET_USE_FANCY_MATH_387"
14001   "* return output_387_reg_move (insn, operands);"
14002   [(set_attr "type" "fmov")
14003    (set_attr "mode" "<MODE>")])
14004
14005 (define_insn "sqrtxf2"
14006   [(set (match_operand:XF 0 "register_operand" "=f")
14007         (sqrt:XF (match_operand:XF 1 "register_operand" "0")))]
14008   "TARGET_USE_FANCY_MATH_387"
14009   "fsqrt"
14010   [(set_attr "type" "fpspc")
14011    (set_attr "mode" "XF")
14012    (set_attr "athlon_decode" "direct")
14013    (set_attr "amdfam10_decode" "direct")
14014    (set_attr "bdver1_decode" "direct")])
14015
14016 (define_insn "sqrt_extend<mode>xf2_i387"
14017   [(set (match_operand:XF 0 "register_operand" "=f")
14018         (sqrt:XF
14019           (float_extend:XF
14020             (match_operand:MODEF 1 "register_operand" "0"))))]
14021   "TARGET_USE_FANCY_MATH_387"
14022   "fsqrt"
14023   [(set_attr "type" "fpspc")
14024    (set_attr "mode" "XF")
14025    (set_attr "athlon_decode" "direct")
14026    (set_attr "amdfam10_decode" "direct")
14027    (set_attr "bdver1_decode" "direct")])
14028
14029 (define_insn "*rsqrtsf2_sse"
14030   [(set (match_operand:SF 0 "register_operand" "=x")
14031         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
14032                    UNSPEC_RSQRT))]
14033   "TARGET_SSE_MATH"
14034   "%vrsqrtss\t{%1, %d0|%d0, %1}"
14035   [(set_attr "type" "sse")
14036    (set_attr "atom_sse_attr" "rcp")
14037    (set_attr "btver2_sse_attr" "rcp")
14038    (set_attr "prefix" "maybe_vex")
14039    (set_attr "mode" "SF")])
14040
14041 (define_expand "rsqrtsf2"
14042   [(set (match_operand:SF 0 "register_operand")
14043         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand")]
14044                    UNSPEC_RSQRT))]
14045   "TARGET_SSE_MATH"
14046 {
14047   ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 1);
14048   DONE;
14049 })
14050
14051 (define_insn "*sqrt<mode>2_sse"
14052   [(set (match_operand:MODEF 0 "register_operand" "=x")
14053         (sqrt:MODEF
14054           (match_operand:MODEF 1 "nonimmediate_operand" "xm")))]
14055   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
14056   "%vsqrt<ssemodesuffix>\t{%1, %d0|%d0, %1}"
14057   [(set_attr "type" "sse")
14058    (set_attr "atom_sse_attr" "sqrt")
14059    (set_attr "btver2_sse_attr" "sqrt")
14060    (set_attr "prefix" "maybe_vex")
14061    (set_attr "mode" "<MODE>")
14062    (set_attr "athlon_decode" "*")
14063    (set_attr "amdfam10_decode" "*")
14064    (set_attr "bdver1_decode" "*")])
14065
14066 (define_expand "sqrt<mode>2"
14067   [(set (match_operand:MODEF 0 "register_operand")
14068         (sqrt:MODEF
14069           (match_operand:MODEF 1 "nonimmediate_operand")))]
14070   "(TARGET_USE_FANCY_MATH_387 && X87_ENABLE_ARITH (<MODE>mode))
14071    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
14072 {
14073   if (<MODE>mode == SFmode
14074       && TARGET_SSE_MATH
14075       && TARGET_RECIP_SQRT
14076       && !optimize_function_for_size_p (cfun)
14077       && flag_finite_math_only && !flag_trapping_math
14078       && flag_unsafe_math_optimizations)
14079     {
14080       ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 0);
14081       DONE;
14082     }
14083
14084   if (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
14085     {
14086       rtx op0 = gen_reg_rtx (XFmode);
14087       rtx op1 = force_reg (<MODE>mode, operands[1]);
14088
14089       emit_insn (gen_sqrt_extend<mode>xf2_i387 (op0, op1));
14090       emit_insn (gen_truncxf<mode>2_i387_noop_unspec (operands[0], op0));
14091       DONE;
14092    }
14093 })
14094
14095 (define_insn "fpremxf4_i387"
14096   [(set (match_operand:XF 0 "register_operand" "=f")
14097         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
14098                     (match_operand:XF 3 "register_operand" "1")]
14099                    UNSPEC_FPREM_F))
14100    (set (match_operand:XF 1 "register_operand" "=u")
14101         (unspec:XF [(match_dup 2) (match_dup 3)]
14102                    UNSPEC_FPREM_U))
14103    (set (reg:CCFP FPSR_REG)
14104         (unspec:CCFP [(match_dup 2) (match_dup 3)]
14105                      UNSPEC_C2_FLAG))]
14106   "TARGET_USE_FANCY_MATH_387
14107    && flag_finite_math_only"
14108   "fprem"
14109   [(set_attr "type" "fpspc")
14110    (set_attr "mode" "XF")])
14111
14112 (define_expand "fmodxf3"
14113   [(use (match_operand:XF 0 "register_operand"))
14114    (use (match_operand:XF 1 "general_operand"))
14115    (use (match_operand:XF 2 "general_operand"))]
14116   "TARGET_USE_FANCY_MATH_387
14117    && flag_finite_math_only"
14118 {
14119   rtx_code_label *label = gen_label_rtx ();
14120
14121   rtx op1 = gen_reg_rtx (XFmode);
14122   rtx op2 = gen_reg_rtx (XFmode);
14123
14124   emit_move_insn (op2, operands[2]);
14125   emit_move_insn (op1, operands[1]);
14126
14127   emit_label (label);
14128   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
14129   ix86_emit_fp_unordered_jump (label);
14130   LABEL_NUSES (label) = 1;
14131
14132   emit_move_insn (operands[0], op1);
14133   DONE;
14134 })
14135
14136 (define_expand "fmod<mode>3"
14137   [(use (match_operand:MODEF 0 "register_operand"))
14138    (use (match_operand:MODEF 1 "general_operand"))
14139    (use (match_operand:MODEF 2 "general_operand"))]
14140   "TARGET_USE_FANCY_MATH_387
14141    && flag_finite_math_only"
14142 {
14143   rtx (*gen_truncxf) (rtx, rtx);
14144
14145   rtx_code_label *label = gen_label_rtx ();
14146
14147   rtx op1 = gen_reg_rtx (XFmode);
14148   rtx op2 = gen_reg_rtx (XFmode);
14149
14150   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
14151   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14152
14153   emit_label (label);
14154   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
14155   ix86_emit_fp_unordered_jump (label);
14156   LABEL_NUSES (label) = 1;
14157
14158   /* Truncate the result properly for strict SSE math.  */
14159   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14160       && !TARGET_MIX_SSE_I387)
14161     gen_truncxf = gen_truncxf<mode>2;
14162   else
14163     gen_truncxf = gen_truncxf<mode>2_i387_noop_unspec;
14164
14165   emit_insn (gen_truncxf (operands[0], op1));
14166   DONE;
14167 })
14168
14169 (define_insn "fprem1xf4_i387"
14170   [(set (match_operand:XF 0 "register_operand" "=f")
14171         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
14172                     (match_operand:XF 3 "register_operand" "1")]
14173                    UNSPEC_FPREM1_F))
14174    (set (match_operand:XF 1 "register_operand" "=u")
14175         (unspec:XF [(match_dup 2) (match_dup 3)]
14176                    UNSPEC_FPREM1_U))
14177    (set (reg:CCFP FPSR_REG)
14178         (unspec:CCFP [(match_dup 2) (match_dup 3)]
14179                      UNSPEC_C2_FLAG))]
14180   "TARGET_USE_FANCY_MATH_387
14181    && flag_finite_math_only"
14182   "fprem1"
14183   [(set_attr "type" "fpspc")
14184    (set_attr "mode" "XF")])
14185
14186 (define_expand "remainderxf3"
14187   [(use (match_operand:XF 0 "register_operand"))
14188    (use (match_operand:XF 1 "general_operand"))
14189    (use (match_operand:XF 2 "general_operand"))]
14190   "TARGET_USE_FANCY_MATH_387
14191    && flag_finite_math_only"
14192 {
14193   rtx_code_label *label = gen_label_rtx ();
14194
14195   rtx op1 = gen_reg_rtx (XFmode);
14196   rtx op2 = gen_reg_rtx (XFmode);
14197
14198   emit_move_insn (op2, operands[2]);
14199   emit_move_insn (op1, operands[1]);
14200
14201   emit_label (label);
14202   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
14203   ix86_emit_fp_unordered_jump (label);
14204   LABEL_NUSES (label) = 1;
14205
14206   emit_move_insn (operands[0], op1);
14207   DONE;
14208 })
14209
14210 (define_expand "remainder<mode>3"
14211   [(use (match_operand:MODEF 0 "register_operand"))
14212    (use (match_operand:MODEF 1 "general_operand"))
14213    (use (match_operand:MODEF 2 "general_operand"))]
14214   "TARGET_USE_FANCY_MATH_387
14215    && flag_finite_math_only"
14216 {
14217   rtx (*gen_truncxf) (rtx, rtx);
14218
14219   rtx_code_label *label = gen_label_rtx ();
14220
14221   rtx op1 = gen_reg_rtx (XFmode);
14222   rtx op2 = gen_reg_rtx (XFmode);
14223
14224   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
14225   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14226
14227   emit_label (label);
14228
14229   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
14230   ix86_emit_fp_unordered_jump (label);
14231   LABEL_NUSES (label) = 1;
14232
14233   /* Truncate the result properly for strict SSE math.  */
14234   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14235       && !TARGET_MIX_SSE_I387)
14236     gen_truncxf = gen_truncxf<mode>2;
14237   else
14238     gen_truncxf = gen_truncxf<mode>2_i387_noop_unspec;
14239
14240   emit_insn (gen_truncxf (operands[0], op1));
14241   DONE;
14242 })
14243
14244 (define_int_iterator SINCOS
14245         [UNSPEC_SIN
14246          UNSPEC_COS])
14247
14248 (define_int_attr sincos
14249         [(UNSPEC_SIN "sin")
14250          (UNSPEC_COS "cos")])
14251
14252 (define_insn "*<sincos>xf2_i387"
14253   [(set (match_operand:XF 0 "register_operand" "=f")
14254         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14255                    SINCOS))]
14256   "TARGET_USE_FANCY_MATH_387
14257    && flag_unsafe_math_optimizations"
14258   "f<sincos>"
14259   [(set_attr "type" "fpspc")
14260    (set_attr "mode" "XF")])
14261
14262 (define_insn "*<sincos>_extend<mode>xf2_i387"
14263   [(set (match_operand:XF 0 "register_operand" "=f")
14264         (unspec:XF [(float_extend:XF
14265                       (match_operand:MODEF 1 "register_operand" "0"))]
14266                    SINCOS))]
14267   "TARGET_USE_FANCY_MATH_387
14268    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14269        || TARGET_MIX_SSE_I387)
14270    && flag_unsafe_math_optimizations"
14271   "f<sincos>"
14272   [(set_attr "type" "fpspc")
14273    (set_attr "mode" "XF")])
14274
14275 ;; When sincos pattern is defined, sin and cos builtin functions will be
14276 ;; expanded to sincos pattern with one of its outputs left unused.
14277 ;; CSE pass will figure out if two sincos patterns can be combined,
14278 ;; otherwise sincos pattern will be split back to sin or cos pattern,
14279 ;; depending on the unused output.
14280
14281 (define_insn "sincosxf3"
14282   [(set (match_operand:XF 0 "register_operand" "=f")
14283         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
14284                    UNSPEC_SINCOS_COS))
14285    (set (match_operand:XF 1 "register_operand" "=u")
14286         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
14287   "TARGET_USE_FANCY_MATH_387
14288    && flag_unsafe_math_optimizations"
14289   "fsincos"
14290   [(set_attr "type" "fpspc")
14291    (set_attr "mode" "XF")])
14292
14293 (define_split
14294   [(set (match_operand:XF 0 "register_operand")
14295         (unspec:XF [(match_operand:XF 2 "register_operand")]
14296                    UNSPEC_SINCOS_COS))
14297    (set (match_operand:XF 1 "register_operand")
14298         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
14299   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
14300    && can_create_pseudo_p ()"
14301   [(set (match_dup 1) (unspec:XF [(match_dup 2)] UNSPEC_SIN))])
14302
14303 (define_split
14304   [(set (match_operand:XF 0 "register_operand")
14305         (unspec:XF [(match_operand:XF 2 "register_operand")]
14306                    UNSPEC_SINCOS_COS))
14307    (set (match_operand:XF 1 "register_operand")
14308         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
14309   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
14310    && can_create_pseudo_p ()"
14311   [(set (match_dup 0) (unspec:XF [(match_dup 2)] UNSPEC_COS))])
14312
14313 (define_insn "sincos_extend<mode>xf3_i387"
14314   [(set (match_operand:XF 0 "register_operand" "=f")
14315         (unspec:XF [(float_extend:XF
14316                       (match_operand:MODEF 2 "register_operand" "0"))]
14317                    UNSPEC_SINCOS_COS))
14318    (set (match_operand:XF 1 "register_operand" "=u")
14319         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
14320   "TARGET_USE_FANCY_MATH_387
14321    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14322        || TARGET_MIX_SSE_I387)
14323    && flag_unsafe_math_optimizations"
14324   "fsincos"
14325   [(set_attr "type" "fpspc")
14326    (set_attr "mode" "XF")])
14327
14328 (define_split
14329   [(set (match_operand:XF 0 "register_operand")
14330         (unspec:XF [(float_extend:XF
14331                       (match_operand:MODEF 2 "register_operand"))]
14332                    UNSPEC_SINCOS_COS))
14333    (set (match_operand:XF 1 "register_operand")
14334         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
14335   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
14336    && can_create_pseudo_p ()"
14337   [(set (match_dup 1)
14338         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SIN))])
14339
14340 (define_split
14341   [(set (match_operand:XF 0 "register_operand")
14342         (unspec:XF [(float_extend:XF
14343                       (match_operand:MODEF 2 "register_operand"))]
14344                    UNSPEC_SINCOS_COS))
14345    (set (match_operand:XF 1 "register_operand")
14346         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
14347   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
14348    && can_create_pseudo_p ()"
14349   [(set (match_dup 0)
14350         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_COS))])
14351
14352 (define_expand "sincos<mode>3"
14353   [(use (match_operand:MODEF 0 "register_operand"))
14354    (use (match_operand:MODEF 1 "register_operand"))
14355    (use (match_operand:MODEF 2 "register_operand"))]
14356   "TARGET_USE_FANCY_MATH_387
14357    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14358        || TARGET_MIX_SSE_I387)
14359    && flag_unsafe_math_optimizations"
14360 {
14361   rtx op0 = gen_reg_rtx (XFmode);
14362   rtx op1 = gen_reg_rtx (XFmode);
14363
14364   emit_insn (gen_sincos_extend<mode>xf3_i387 (op0, op1, operands[2]));
14365   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14366   emit_insn (gen_truncxf<mode>2_i387_noop (operands[1], op1));
14367   DONE;
14368 })
14369
14370 (define_insn "fptanxf4_i387"
14371   [(set (match_operand:XF 0 "register_operand" "=f")
14372         (match_operand:XF 3 "const_double_operand" "F"))
14373    (set (match_operand:XF 1 "register_operand" "=u")
14374         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
14375                    UNSPEC_TAN))]
14376   "TARGET_USE_FANCY_MATH_387
14377    && flag_unsafe_math_optimizations
14378    && standard_80387_constant_p (operands[3]) == 2"
14379   "fptan"
14380   [(set_attr "type" "fpspc")
14381    (set_attr "mode" "XF")])
14382
14383 (define_insn "fptan_extend<mode>xf4_i387"
14384   [(set (match_operand:MODEF 0 "register_operand" "=f")
14385         (match_operand:MODEF 3 "const_double_operand" "F"))
14386    (set (match_operand:XF 1 "register_operand" "=u")
14387         (unspec:XF [(float_extend:XF
14388                       (match_operand:MODEF 2 "register_operand" "0"))]
14389                    UNSPEC_TAN))]
14390   "TARGET_USE_FANCY_MATH_387
14391    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14392        || TARGET_MIX_SSE_I387)
14393    && flag_unsafe_math_optimizations
14394    && standard_80387_constant_p (operands[3]) == 2"
14395   "fptan"
14396   [(set_attr "type" "fpspc")
14397    (set_attr "mode" "XF")])
14398
14399 (define_expand "tanxf2"
14400   [(use (match_operand:XF 0 "register_operand"))
14401    (use (match_operand:XF 1 "register_operand"))]
14402   "TARGET_USE_FANCY_MATH_387
14403    && flag_unsafe_math_optimizations"
14404 {
14405   rtx one = gen_reg_rtx (XFmode);
14406   rtx op2 = CONST1_RTX (XFmode); /* fld1 */
14407
14408   emit_insn (gen_fptanxf4_i387 (one, operands[0], operands[1], op2));
14409   DONE;
14410 })
14411
14412 (define_expand "tan<mode>2"
14413   [(use (match_operand:MODEF 0 "register_operand"))
14414    (use (match_operand:MODEF 1 "register_operand"))]
14415   "TARGET_USE_FANCY_MATH_387
14416    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14417        || TARGET_MIX_SSE_I387)
14418    && flag_unsafe_math_optimizations"
14419 {
14420   rtx op0 = gen_reg_rtx (XFmode);
14421
14422   rtx one = gen_reg_rtx (<MODE>mode);
14423   rtx op2 = CONST1_RTX (<MODE>mode); /* fld1 */
14424
14425   emit_insn (gen_fptan_extend<mode>xf4_i387 (one, op0,
14426                                              operands[1], op2));
14427   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14428   DONE;
14429 })
14430
14431 (define_insn "*fpatanxf3_i387"
14432   [(set (match_operand:XF 0 "register_operand" "=f")
14433         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
14434                     (match_operand:XF 2 "register_operand" "u")]
14435                    UNSPEC_FPATAN))
14436    (clobber (match_scratch:XF 3 "=2"))]
14437   "TARGET_USE_FANCY_MATH_387
14438    && flag_unsafe_math_optimizations"
14439   "fpatan"
14440   [(set_attr "type" "fpspc")
14441    (set_attr "mode" "XF")])
14442
14443 (define_insn "fpatan_extend<mode>xf3_i387"
14444   [(set (match_operand:XF 0 "register_operand" "=f")
14445         (unspec:XF [(float_extend:XF
14446                       (match_operand:MODEF 1 "register_operand" "0"))
14447                     (float_extend:XF
14448                       (match_operand:MODEF 2 "register_operand" "u"))]
14449                    UNSPEC_FPATAN))
14450    (clobber (match_scratch:XF 3 "=2"))]
14451   "TARGET_USE_FANCY_MATH_387
14452    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14453        || TARGET_MIX_SSE_I387)
14454    && flag_unsafe_math_optimizations"
14455   "fpatan"
14456   [(set_attr "type" "fpspc")
14457    (set_attr "mode" "XF")])
14458
14459 (define_expand "atan2xf3"
14460   [(parallel [(set (match_operand:XF 0 "register_operand")
14461                    (unspec:XF [(match_operand:XF 2 "register_operand")
14462                                (match_operand:XF 1 "register_operand")]
14463                               UNSPEC_FPATAN))
14464               (clobber (match_scratch:XF 3))])]
14465   "TARGET_USE_FANCY_MATH_387
14466    && flag_unsafe_math_optimizations")
14467
14468 (define_expand "atan2<mode>3"
14469   [(use (match_operand:MODEF 0 "register_operand"))
14470    (use (match_operand:MODEF 1 "register_operand"))
14471    (use (match_operand:MODEF 2 "register_operand"))]
14472   "TARGET_USE_FANCY_MATH_387
14473    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14474        || TARGET_MIX_SSE_I387)
14475    && flag_unsafe_math_optimizations"
14476 {
14477   rtx op0 = gen_reg_rtx (XFmode);
14478
14479   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, operands[2], operands[1]));
14480   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14481   DONE;
14482 })
14483
14484 (define_expand "atanxf2"
14485   [(parallel [(set (match_operand:XF 0 "register_operand")
14486                    (unspec:XF [(match_dup 2)
14487                                (match_operand:XF 1 "register_operand")]
14488                               UNSPEC_FPATAN))
14489               (clobber (match_scratch:XF 3))])]
14490   "TARGET_USE_FANCY_MATH_387
14491    && flag_unsafe_math_optimizations"
14492 {
14493   operands[2] = gen_reg_rtx (XFmode);
14494   emit_move_insn (operands[2], CONST1_RTX (XFmode));  /* fld1 */
14495 })
14496
14497 (define_expand "atan<mode>2"
14498   [(use (match_operand:MODEF 0 "register_operand"))
14499    (use (match_operand:MODEF 1 "register_operand"))]
14500   "TARGET_USE_FANCY_MATH_387
14501    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14502        || TARGET_MIX_SSE_I387)
14503    && flag_unsafe_math_optimizations"
14504 {
14505   rtx op0 = gen_reg_rtx (XFmode);
14506
14507   rtx op2 = gen_reg_rtx (<MODE>mode);
14508   emit_move_insn (op2, CONST1_RTX (<MODE>mode));  /* fld1 */
14509
14510   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, op2, operands[1]));
14511   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14512   DONE;
14513 })
14514
14515 (define_expand "asinxf2"
14516   [(set (match_dup 2)
14517         (mult:XF (match_operand:XF 1 "register_operand")
14518                  (match_dup 1)))
14519    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
14520    (set (match_dup 5) (sqrt:XF (match_dup 4)))
14521    (parallel [(set (match_operand:XF 0 "register_operand")
14522                    (unspec:XF [(match_dup 5) (match_dup 1)]
14523                               UNSPEC_FPATAN))
14524               (clobber (match_scratch:XF 6))])]
14525   "TARGET_USE_FANCY_MATH_387
14526    && flag_unsafe_math_optimizations"
14527 {
14528   int i;
14529
14530   if (optimize_insn_for_size_p ())
14531     FAIL;
14532
14533   for (i = 2; i < 6; i++)
14534     operands[i] = gen_reg_rtx (XFmode);
14535
14536   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
14537 })
14538
14539 (define_expand "asin<mode>2"
14540   [(use (match_operand:MODEF 0 "register_operand"))
14541    (use (match_operand:MODEF 1 "general_operand"))]
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 {
14547   rtx op0 = gen_reg_rtx (XFmode);
14548   rtx op1 = gen_reg_rtx (XFmode);
14549
14550   if (optimize_insn_for_size_p ())
14551     FAIL;
14552
14553   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14554   emit_insn (gen_asinxf2 (op0, op1));
14555   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14556   DONE;
14557 })
14558
14559 (define_expand "acosxf2"
14560   [(set (match_dup 2)
14561         (mult:XF (match_operand:XF 1 "register_operand")
14562                  (match_dup 1)))
14563    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
14564    (set (match_dup 5) (sqrt:XF (match_dup 4)))
14565    (parallel [(set (match_operand:XF 0 "register_operand")
14566                    (unspec:XF [(match_dup 1) (match_dup 5)]
14567                               UNSPEC_FPATAN))
14568               (clobber (match_scratch:XF 6))])]
14569   "TARGET_USE_FANCY_MATH_387
14570    && flag_unsafe_math_optimizations"
14571 {
14572   int i;
14573
14574   if (optimize_insn_for_size_p ())
14575     FAIL;
14576
14577   for (i = 2; i < 6; i++)
14578     operands[i] = gen_reg_rtx (XFmode);
14579
14580   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
14581 })
14582
14583 (define_expand "acos<mode>2"
14584   [(use (match_operand:MODEF 0 "register_operand"))
14585    (use (match_operand:MODEF 1 "general_operand"))]
14586  "TARGET_USE_FANCY_MATH_387
14587    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14588        || TARGET_MIX_SSE_I387)
14589    && flag_unsafe_math_optimizations"
14590 {
14591   rtx op0 = gen_reg_rtx (XFmode);
14592   rtx op1 = gen_reg_rtx (XFmode);
14593
14594   if (optimize_insn_for_size_p ())
14595     FAIL;
14596
14597   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14598   emit_insn (gen_acosxf2 (op0, op1));
14599   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14600   DONE;
14601 })
14602
14603 (define_insn "fyl2xxf3_i387"
14604   [(set (match_operand:XF 0 "register_operand" "=f")
14605         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
14606                     (match_operand:XF 2 "register_operand" "u")]
14607                    UNSPEC_FYL2X))
14608    (clobber (match_scratch:XF 3 "=2"))]
14609   "TARGET_USE_FANCY_MATH_387
14610    && flag_unsafe_math_optimizations"
14611   "fyl2x"
14612   [(set_attr "type" "fpspc")
14613    (set_attr "mode" "XF")])
14614
14615 (define_insn "fyl2x_extend<mode>xf3_i387"
14616   [(set (match_operand:XF 0 "register_operand" "=f")
14617         (unspec:XF [(float_extend:XF
14618                       (match_operand:MODEF 1 "register_operand" "0"))
14619                     (match_operand:XF 2 "register_operand" "u")]
14620                    UNSPEC_FYL2X))
14621    (clobber (match_scratch:XF 3 "=2"))]
14622   "TARGET_USE_FANCY_MATH_387
14623    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14624        || TARGET_MIX_SSE_I387)
14625    && flag_unsafe_math_optimizations"
14626   "fyl2x"
14627   [(set_attr "type" "fpspc")
14628    (set_attr "mode" "XF")])
14629
14630 (define_expand "logxf2"
14631   [(parallel [(set (match_operand:XF 0 "register_operand")
14632                    (unspec:XF [(match_operand:XF 1 "register_operand")
14633                                (match_dup 2)] UNSPEC_FYL2X))
14634               (clobber (match_scratch:XF 3))])]
14635   "TARGET_USE_FANCY_MATH_387
14636    && flag_unsafe_math_optimizations"
14637 {
14638   operands[2] = gen_reg_rtx (XFmode);
14639   emit_move_insn (operands[2], standard_80387_constant_rtx (4)); /* fldln2 */
14640 })
14641
14642 (define_expand "log<mode>2"
14643   [(use (match_operand:MODEF 0 "register_operand"))
14644    (use (match_operand:MODEF 1 "register_operand"))]
14645   "TARGET_USE_FANCY_MATH_387
14646    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14647        || TARGET_MIX_SSE_I387)
14648    && flag_unsafe_math_optimizations"
14649 {
14650   rtx op0 = gen_reg_rtx (XFmode);
14651
14652   rtx op2 = gen_reg_rtx (XFmode);
14653   emit_move_insn (op2, standard_80387_constant_rtx (4)); /* fldln2 */
14654
14655   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
14656   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14657   DONE;
14658 })
14659
14660 (define_expand "log10xf2"
14661   [(parallel [(set (match_operand:XF 0 "register_operand")
14662                    (unspec:XF [(match_operand:XF 1 "register_operand")
14663                                (match_dup 2)] UNSPEC_FYL2X))
14664               (clobber (match_scratch:XF 3))])]
14665   "TARGET_USE_FANCY_MATH_387
14666    && flag_unsafe_math_optimizations"
14667 {
14668   operands[2] = gen_reg_rtx (XFmode);
14669   emit_move_insn (operands[2], standard_80387_constant_rtx (3)); /* fldlg2 */
14670 })
14671
14672 (define_expand "log10<mode>2"
14673   [(use (match_operand:MODEF 0 "register_operand"))
14674    (use (match_operand:MODEF 1 "register_operand"))]
14675   "TARGET_USE_FANCY_MATH_387
14676    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14677        || TARGET_MIX_SSE_I387)
14678    && flag_unsafe_math_optimizations"
14679 {
14680   rtx op0 = gen_reg_rtx (XFmode);
14681
14682   rtx op2 = gen_reg_rtx (XFmode);
14683   emit_move_insn (op2, standard_80387_constant_rtx (3)); /* fldlg2 */
14684
14685   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
14686   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14687   DONE;
14688 })
14689
14690 (define_expand "log2xf2"
14691   [(parallel [(set (match_operand:XF 0 "register_operand")
14692                    (unspec:XF [(match_operand:XF 1 "register_operand")
14693                                (match_dup 2)] UNSPEC_FYL2X))
14694               (clobber (match_scratch:XF 3))])]
14695   "TARGET_USE_FANCY_MATH_387
14696    && flag_unsafe_math_optimizations"
14697 {
14698   operands[2] = gen_reg_rtx (XFmode);
14699   emit_move_insn (operands[2], CONST1_RTX (XFmode)); /* fld1 */
14700 })
14701
14702 (define_expand "log2<mode>2"
14703   [(use (match_operand:MODEF 0 "register_operand"))
14704    (use (match_operand:MODEF 1 "register_operand"))]
14705   "TARGET_USE_FANCY_MATH_387
14706    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14707        || TARGET_MIX_SSE_I387)
14708    && flag_unsafe_math_optimizations"
14709 {
14710   rtx op0 = gen_reg_rtx (XFmode);
14711
14712   rtx op2 = gen_reg_rtx (XFmode);
14713   emit_move_insn (op2, CONST1_RTX (XFmode)); /* fld1 */
14714
14715   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
14716   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14717   DONE;
14718 })
14719
14720 (define_insn "fyl2xp1xf3_i387"
14721   [(set (match_operand:XF 0 "register_operand" "=f")
14722         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
14723                     (match_operand:XF 2 "register_operand" "u")]
14724                    UNSPEC_FYL2XP1))
14725    (clobber (match_scratch:XF 3 "=2"))]
14726   "TARGET_USE_FANCY_MATH_387
14727    && flag_unsafe_math_optimizations"
14728   "fyl2xp1"
14729   [(set_attr "type" "fpspc")
14730    (set_attr "mode" "XF")])
14731
14732 (define_insn "fyl2xp1_extend<mode>xf3_i387"
14733   [(set (match_operand:XF 0 "register_operand" "=f")
14734         (unspec:XF [(float_extend:XF
14735                       (match_operand:MODEF 1 "register_operand" "0"))
14736                     (match_operand:XF 2 "register_operand" "u")]
14737                    UNSPEC_FYL2XP1))
14738    (clobber (match_scratch:XF 3 "=2"))]
14739   "TARGET_USE_FANCY_MATH_387
14740    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14741        || TARGET_MIX_SSE_I387)
14742    && flag_unsafe_math_optimizations"
14743   "fyl2xp1"
14744   [(set_attr "type" "fpspc")
14745    (set_attr "mode" "XF")])
14746
14747 (define_expand "log1pxf2"
14748   [(use (match_operand:XF 0 "register_operand"))
14749    (use (match_operand:XF 1 "register_operand"))]
14750   "TARGET_USE_FANCY_MATH_387
14751    && flag_unsafe_math_optimizations"
14752 {
14753   if (optimize_insn_for_size_p ())
14754     FAIL;
14755
14756   ix86_emit_i387_log1p (operands[0], operands[1]);
14757   DONE;
14758 })
14759
14760 (define_expand "log1p<mode>2"
14761   [(use (match_operand:MODEF 0 "register_operand"))
14762    (use (match_operand:MODEF 1 "register_operand"))]
14763   "TARGET_USE_FANCY_MATH_387
14764    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14765        || TARGET_MIX_SSE_I387)
14766    && flag_unsafe_math_optimizations"
14767 {
14768   rtx op0;
14769
14770   if (optimize_insn_for_size_p ())
14771     FAIL;
14772
14773   op0 = gen_reg_rtx (XFmode);
14774
14775   operands[1] = gen_rtx_FLOAT_EXTEND (XFmode, operands[1]);
14776
14777   ix86_emit_i387_log1p (op0, operands[1]);
14778   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14779   DONE;
14780 })
14781
14782 (define_insn "fxtractxf3_i387"
14783   [(set (match_operand:XF 0 "register_operand" "=f")
14784         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
14785                    UNSPEC_XTRACT_FRACT))
14786    (set (match_operand:XF 1 "register_operand" "=u")
14787         (unspec:XF [(match_dup 2)] UNSPEC_XTRACT_EXP))]
14788   "TARGET_USE_FANCY_MATH_387
14789    && flag_unsafe_math_optimizations"
14790   "fxtract"
14791   [(set_attr "type" "fpspc")
14792    (set_attr "mode" "XF")])
14793
14794 (define_insn "fxtract_extend<mode>xf3_i387"
14795   [(set (match_operand:XF 0 "register_operand" "=f")
14796         (unspec:XF [(float_extend:XF
14797                       (match_operand:MODEF 2 "register_operand" "0"))]
14798                    UNSPEC_XTRACT_FRACT))
14799    (set (match_operand:XF 1 "register_operand" "=u")
14800         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_XTRACT_EXP))]
14801   "TARGET_USE_FANCY_MATH_387
14802    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14803        || TARGET_MIX_SSE_I387)
14804    && flag_unsafe_math_optimizations"
14805   "fxtract"
14806   [(set_attr "type" "fpspc")
14807    (set_attr "mode" "XF")])
14808
14809 (define_expand "logbxf2"
14810   [(parallel [(set (match_dup 2)
14811                    (unspec:XF [(match_operand:XF 1 "register_operand")]
14812                               UNSPEC_XTRACT_FRACT))
14813               (set (match_operand:XF 0 "register_operand")
14814                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
14815   "TARGET_USE_FANCY_MATH_387
14816    && flag_unsafe_math_optimizations"
14817   "operands[2] = gen_reg_rtx (XFmode);")
14818
14819 (define_expand "logb<mode>2"
14820   [(use (match_operand:MODEF 0 "register_operand"))
14821    (use (match_operand:MODEF 1 "register_operand"))]
14822   "TARGET_USE_FANCY_MATH_387
14823    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14824        || TARGET_MIX_SSE_I387)
14825    && flag_unsafe_math_optimizations"
14826 {
14827   rtx op0 = gen_reg_rtx (XFmode);
14828   rtx op1 = gen_reg_rtx (XFmode);
14829
14830   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
14831   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op1));
14832   DONE;
14833 })
14834
14835 (define_expand "ilogbxf2"
14836   [(use (match_operand:SI 0 "register_operand"))
14837    (use (match_operand:XF 1 "register_operand"))]
14838   "TARGET_USE_FANCY_MATH_387
14839    && flag_unsafe_math_optimizations"
14840 {
14841   rtx op0, op1;
14842
14843   if (optimize_insn_for_size_p ())
14844     FAIL;
14845
14846   op0 = gen_reg_rtx (XFmode);
14847   op1 = gen_reg_rtx (XFmode);
14848
14849   emit_insn (gen_fxtractxf3_i387 (op0, op1, operands[1]));
14850   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
14851   DONE;
14852 })
14853
14854 (define_expand "ilogb<mode>2"
14855   [(use (match_operand:SI 0 "register_operand"))
14856    (use (match_operand:MODEF 1 "register_operand"))]
14857   "TARGET_USE_FANCY_MATH_387
14858    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14859        || TARGET_MIX_SSE_I387)
14860    && flag_unsafe_math_optimizations"
14861 {
14862   rtx op0, op1;
14863
14864   if (optimize_insn_for_size_p ())
14865     FAIL;
14866
14867   op0 = gen_reg_rtx (XFmode);
14868   op1 = gen_reg_rtx (XFmode);
14869
14870   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
14871   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
14872   DONE;
14873 })
14874
14875 (define_insn "*f2xm1xf2_i387"
14876   [(set (match_operand:XF 0 "register_operand" "=f")
14877         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14878                    UNSPEC_F2XM1))]
14879   "TARGET_USE_FANCY_MATH_387
14880    && flag_unsafe_math_optimizations"
14881   "f2xm1"
14882   [(set_attr "type" "fpspc")
14883    (set_attr "mode" "XF")])
14884
14885 (define_insn "fscalexf4_i387"
14886   [(set (match_operand:XF 0 "register_operand" "=f")
14887         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
14888                     (match_operand:XF 3 "register_operand" "1")]
14889                    UNSPEC_FSCALE_FRACT))
14890    (set (match_operand:XF 1 "register_operand" "=u")
14891         (unspec:XF [(match_dup 2) (match_dup 3)]
14892                    UNSPEC_FSCALE_EXP))]
14893   "TARGET_USE_FANCY_MATH_387
14894    && flag_unsafe_math_optimizations"
14895   "fscale"
14896   [(set_attr "type" "fpspc")
14897    (set_attr "mode" "XF")])
14898
14899 (define_expand "expNcorexf3"
14900   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand")
14901                                (match_operand:XF 2 "register_operand")))
14902    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
14903    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
14904    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
14905    (set (match_dup 8) (plus:XF (match_dup 6) (match_dup 7)))
14906    (parallel [(set (match_operand:XF 0 "register_operand")
14907                    (unspec:XF [(match_dup 8) (match_dup 4)]
14908                               UNSPEC_FSCALE_FRACT))
14909               (set (match_dup 9)
14910                    (unspec:XF [(match_dup 8) (match_dup 4)]
14911                               UNSPEC_FSCALE_EXP))])]
14912   "TARGET_USE_FANCY_MATH_387
14913    && flag_unsafe_math_optimizations"
14914 {
14915   int i;
14916
14917   if (optimize_insn_for_size_p ())
14918     FAIL;
14919
14920   for (i = 3; i < 10; i++)
14921     operands[i] = gen_reg_rtx (XFmode);
14922
14923   emit_move_insn (operands[7], CONST1_RTX (XFmode));  /* fld1 */
14924 })
14925
14926 (define_expand "expxf2"
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, standard_80387_constant_rtx (5)); /* fldl2e */
14939
14940   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14941   DONE;
14942 })
14943
14944 (define_expand "exp<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_expxf2 (op0, op1));
14962   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14963   DONE;
14964 })
14965
14966 (define_expand "exp10xf2"
14967   [(use (match_operand:XF 0 "register_operand"))
14968    (use (match_operand:XF 1 "register_operand"))]
14969   "TARGET_USE_FANCY_MATH_387
14970    && flag_unsafe_math_optimizations"
14971 {
14972   rtx op2;
14973
14974   if (optimize_insn_for_size_p ())
14975     FAIL;
14976
14977   op2 = gen_reg_rtx (XFmode);
14978   emit_move_insn (op2, standard_80387_constant_rtx (6)); /* fldl2t */
14979
14980   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14981   DONE;
14982 })
14983
14984 (define_expand "exp10<mode>2"
14985   [(use (match_operand:MODEF 0 "register_operand"))
14986    (use (match_operand:MODEF 1 "general_operand"))]
14987  "TARGET_USE_FANCY_MATH_387
14988    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14989        || TARGET_MIX_SSE_I387)
14990    && flag_unsafe_math_optimizations"
14991 {
14992   rtx op0, op1;
14993
14994   if (optimize_insn_for_size_p ())
14995     FAIL;
14996
14997   op0 = gen_reg_rtx (XFmode);
14998   op1 = gen_reg_rtx (XFmode);
14999
15000   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15001   emit_insn (gen_exp10xf2 (op0, op1));
15002   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15003   DONE;
15004 })
15005
15006 (define_expand "exp2xf2"
15007   [(use (match_operand:XF 0 "register_operand"))
15008    (use (match_operand:XF 1 "register_operand"))]
15009   "TARGET_USE_FANCY_MATH_387
15010    && flag_unsafe_math_optimizations"
15011 {
15012   rtx op2;
15013
15014   if (optimize_insn_for_size_p ())
15015     FAIL;
15016
15017   op2 = gen_reg_rtx (XFmode);
15018   emit_move_insn (op2, CONST1_RTX (XFmode));  /* fld1 */
15019
15020   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
15021   DONE;
15022 })
15023
15024 (define_expand "exp2<mode>2"
15025   [(use (match_operand:MODEF 0 "register_operand"))
15026    (use (match_operand:MODEF 1 "general_operand"))]
15027  "TARGET_USE_FANCY_MATH_387
15028    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15029        || TARGET_MIX_SSE_I387)
15030    && flag_unsafe_math_optimizations"
15031 {
15032   rtx op0, op1;
15033
15034   if (optimize_insn_for_size_p ())
15035     FAIL;
15036
15037   op0 = gen_reg_rtx (XFmode);
15038   op1 = gen_reg_rtx (XFmode);
15039
15040   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15041   emit_insn (gen_exp2xf2 (op0, op1));
15042   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15043   DONE;
15044 })
15045
15046 (define_expand "expm1xf2"
15047   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand")
15048                                (match_dup 2)))
15049    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
15050    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
15051    (set (match_dup 9) (float_extend:XF (match_dup 13)))
15052    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
15053    (parallel [(set (match_dup 7)
15054                    (unspec:XF [(match_dup 6) (match_dup 4)]
15055                               UNSPEC_FSCALE_FRACT))
15056               (set (match_dup 8)
15057                    (unspec:XF [(match_dup 6) (match_dup 4)]
15058                               UNSPEC_FSCALE_EXP))])
15059    (parallel [(set (match_dup 10)
15060                    (unspec:XF [(match_dup 9) (match_dup 8)]
15061                               UNSPEC_FSCALE_FRACT))
15062               (set (match_dup 11)
15063                    (unspec:XF [(match_dup 9) (match_dup 8)]
15064                               UNSPEC_FSCALE_EXP))])
15065    (set (match_dup 12) (minus:XF (match_dup 10)
15066                                  (float_extend:XF (match_dup 13))))
15067    (set (match_operand:XF 0 "register_operand")
15068         (plus:XF (match_dup 12) (match_dup 7)))]
15069   "TARGET_USE_FANCY_MATH_387
15070    && flag_unsafe_math_optimizations"
15071 {
15072   int i;
15073
15074   if (optimize_insn_for_size_p ())
15075     FAIL;
15076
15077   for (i = 2; i < 13; i++)
15078     operands[i] = gen_reg_rtx (XFmode);
15079
15080   operands[13]
15081     = validize_mem (force_const_mem (SFmode, CONST1_RTX (SFmode))); /* fld1 */
15082
15083   emit_move_insn (operands[2], standard_80387_constant_rtx (5)); /* fldl2e */
15084 })
15085
15086 (define_expand "expm1<mode>2"
15087   [(use (match_operand:MODEF 0 "register_operand"))
15088    (use (match_operand:MODEF 1 "general_operand"))]
15089  "TARGET_USE_FANCY_MATH_387
15090    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15091        || TARGET_MIX_SSE_I387)
15092    && flag_unsafe_math_optimizations"
15093 {
15094   rtx op0, op1;
15095
15096   if (optimize_insn_for_size_p ())
15097     FAIL;
15098
15099   op0 = gen_reg_rtx (XFmode);
15100   op1 = gen_reg_rtx (XFmode);
15101
15102   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15103   emit_insn (gen_expm1xf2 (op0, op1));
15104   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15105   DONE;
15106 })
15107
15108 (define_expand "ldexpxf3"
15109   [(match_operand:XF 0 "register_operand")
15110    (match_operand:XF 1 "register_operand")
15111    (match_operand:SI 2 "register_operand")]
15112   "TARGET_USE_FANCY_MATH_387
15113    && flag_unsafe_math_optimizations"
15114 {
15115   rtx tmp1, tmp2;
15116   if (optimize_insn_for_size_p ())
15117     FAIL;
15118
15119   tmp1 = gen_reg_rtx (XFmode);
15120   tmp2 = gen_reg_rtx (XFmode);
15121
15122   emit_insn (gen_floatsixf2 (tmp1, operands[2]));
15123   emit_insn (gen_fscalexf4_i387 (operands[0], tmp2,
15124                                  operands[1], tmp1));
15125   DONE;
15126 })
15127
15128 (define_expand "ldexp<mode>3"
15129   [(use (match_operand:MODEF 0 "register_operand"))
15130    (use (match_operand:MODEF 1 "general_operand"))
15131    (use (match_operand:SI 2 "register_operand"))]
15132  "TARGET_USE_FANCY_MATH_387
15133    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15134        || TARGET_MIX_SSE_I387)
15135    && flag_unsafe_math_optimizations"
15136 {
15137   rtx op0, op1;
15138
15139   if (optimize_insn_for_size_p ())
15140     FAIL;
15141
15142   op0 = gen_reg_rtx (XFmode);
15143   op1 = gen_reg_rtx (XFmode);
15144
15145   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15146   emit_insn (gen_ldexpxf3 (op0, op1, operands[2]));
15147   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15148   DONE;
15149 })
15150
15151 (define_expand "scalbxf3"
15152   [(parallel [(set (match_operand:XF 0 " register_operand")
15153                    (unspec:XF [(match_operand:XF 1 "register_operand")
15154                                (match_operand:XF 2 "register_operand")]
15155                               UNSPEC_FSCALE_FRACT))
15156               (set (match_dup 3)
15157                    (unspec:XF [(match_dup 1) (match_dup 2)]
15158                               UNSPEC_FSCALE_EXP))])]
15159   "TARGET_USE_FANCY_MATH_387
15160    && flag_unsafe_math_optimizations"
15161 {
15162   if (optimize_insn_for_size_p ())
15163     FAIL;
15164
15165   operands[3] = gen_reg_rtx (XFmode);
15166 })
15167
15168 (define_expand "scalb<mode>3"
15169   [(use (match_operand:MODEF 0 "register_operand"))
15170    (use (match_operand:MODEF 1 "general_operand"))
15171    (use (match_operand:MODEF 2 "general_operand"))]
15172  "TARGET_USE_FANCY_MATH_387
15173    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15174        || TARGET_MIX_SSE_I387)
15175    && flag_unsafe_math_optimizations"
15176 {
15177   rtx op0, op1, op2;
15178
15179   if (optimize_insn_for_size_p ())
15180     FAIL;
15181
15182   op0 = gen_reg_rtx (XFmode);
15183   op1 = gen_reg_rtx (XFmode);
15184   op2 = gen_reg_rtx (XFmode);
15185
15186   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15187   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
15188   emit_insn (gen_scalbxf3 (op0, op1, op2));
15189   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15190   DONE;
15191 })
15192
15193 (define_expand "significandxf2"
15194   [(parallel [(set (match_operand:XF 0 "register_operand")
15195                    (unspec:XF [(match_operand:XF 1 "register_operand")]
15196                               UNSPEC_XTRACT_FRACT))
15197               (set (match_dup 2)
15198                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
15199   "TARGET_USE_FANCY_MATH_387
15200    && flag_unsafe_math_optimizations"
15201   "operands[2] = gen_reg_rtx (XFmode);")
15202
15203 (define_expand "significand<mode>2"
15204   [(use (match_operand:MODEF 0 "register_operand"))
15205    (use (match_operand:MODEF 1 "register_operand"))]
15206   "TARGET_USE_FANCY_MATH_387
15207    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15208        || TARGET_MIX_SSE_I387)
15209    && flag_unsafe_math_optimizations"
15210 {
15211   rtx op0 = gen_reg_rtx (XFmode);
15212   rtx op1 = gen_reg_rtx (XFmode);
15213
15214   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
15215   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15216   DONE;
15217 })
15218 \f
15219
15220 (define_insn "sse4_1_round<mode>2"
15221   [(set (match_operand:MODEF 0 "register_operand" "=x")
15222         (unspec:MODEF [(match_operand:MODEF 1 "register_operand" "x")
15223                        (match_operand:SI 2 "const_0_to_15_operand" "n")]
15224                       UNSPEC_ROUND))]
15225   "TARGET_ROUND"
15226   "%vround<ssemodesuffix>\t{%2, %1, %d0|%d0, %1, %2}"
15227   [(set_attr "type" "ssecvt")
15228    (set_attr "prefix_extra" "1")
15229    (set_attr "prefix" "maybe_vex")
15230    (set_attr "mode" "<MODE>")])
15231
15232 (define_insn "rintxf2"
15233   [(set (match_operand:XF 0 "register_operand" "=f")
15234         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15235                    UNSPEC_FRNDINT))]
15236   "TARGET_USE_FANCY_MATH_387
15237    && flag_unsafe_math_optimizations"
15238   "frndint"
15239   [(set_attr "type" "fpspc")
15240    (set_attr "mode" "XF")])
15241
15242 (define_expand "rint<mode>2"
15243   [(use (match_operand:MODEF 0 "register_operand"))
15244    (use (match_operand:MODEF 1 "register_operand"))]
15245   "(TARGET_USE_FANCY_MATH_387
15246     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15247         || TARGET_MIX_SSE_I387)
15248     && flag_unsafe_math_optimizations)
15249    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15250        && !flag_trapping_math)"
15251 {
15252   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15253       && !flag_trapping_math)
15254     {
15255       if (TARGET_ROUND)
15256         emit_insn (gen_sse4_1_round<mode>2
15257                    (operands[0], operands[1], GEN_INT (ROUND_MXCSR)));
15258       else if (optimize_insn_for_size_p ())
15259         FAIL;
15260       else
15261         ix86_expand_rint (operands[0], operands[1]);
15262     }
15263   else
15264     {
15265       rtx op0 = gen_reg_rtx (XFmode);
15266       rtx op1 = gen_reg_rtx (XFmode);
15267
15268       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15269       emit_insn (gen_rintxf2 (op0, op1));
15270
15271       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15272     }
15273   DONE;
15274 })
15275
15276 (define_expand "round<mode>2"
15277   [(match_operand:X87MODEF 0 "register_operand")
15278    (match_operand:X87MODEF 1 "nonimmediate_operand")]
15279   "(TARGET_USE_FANCY_MATH_387
15280     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15281         || TARGET_MIX_SSE_I387)
15282     && flag_unsafe_math_optimizations)
15283    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15284        && !flag_trapping_math && !flag_rounding_math)"
15285 {
15286   if (optimize_insn_for_size_p ())
15287     FAIL;
15288
15289   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15290       && !flag_trapping_math && !flag_rounding_math)
15291     {
15292       if (TARGET_ROUND)
15293         {
15294           operands[1] = force_reg (<MODE>mode, operands[1]);
15295           ix86_expand_round_sse4 (operands[0], operands[1]);
15296         }
15297       else if (TARGET_64BIT || (<MODE>mode != DFmode))
15298         ix86_expand_round (operands[0], operands[1]);
15299       else
15300         ix86_expand_rounddf_32 (operands[0], operands[1]);
15301     }
15302   else
15303     {
15304       operands[1] = force_reg (<MODE>mode, operands[1]);
15305       ix86_emit_i387_round (operands[0], operands[1]);
15306     }
15307   DONE;
15308 })
15309
15310 (define_insn_and_split "*fistdi2_1"
15311   [(set (match_operand:DI 0 "nonimmediate_operand")
15312         (unspec:DI [(match_operand:XF 1 "register_operand")]
15313                    UNSPEC_FIST))]
15314   "TARGET_USE_FANCY_MATH_387
15315    && can_create_pseudo_p ()"
15316   "#"
15317   "&& 1"
15318   [(const_int 0)]
15319 {
15320   if (memory_operand (operands[0], VOIDmode))
15321     emit_insn (gen_fistdi2 (operands[0], operands[1]));
15322   else
15323     {
15324       operands[2] = assign_386_stack_local (DImode, SLOT_TEMP);
15325       emit_insn (gen_fistdi2_with_temp (operands[0], operands[1],
15326                                          operands[2]));
15327     }
15328   DONE;
15329 }
15330   [(set_attr "type" "fpspc")
15331    (set_attr "mode" "DI")])
15332
15333 (define_insn "fistdi2"
15334   [(set (match_operand:DI 0 "memory_operand" "=m")
15335         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
15336                    UNSPEC_FIST))
15337    (clobber (match_scratch:XF 2 "=&1f"))]
15338   "TARGET_USE_FANCY_MATH_387"
15339   "* return output_fix_trunc (insn, operands, false);"
15340   [(set_attr "type" "fpspc")
15341    (set_attr "mode" "DI")])
15342
15343 (define_insn "fistdi2_with_temp"
15344   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
15345         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
15346                    UNSPEC_FIST))
15347    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))
15348    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
15349   "TARGET_USE_FANCY_MATH_387"
15350   "#"
15351   [(set_attr "type" "fpspc")
15352    (set_attr "mode" "DI")])
15353
15354 (define_split
15355   [(set (match_operand:DI 0 "register_operand")
15356         (unspec:DI [(match_operand:XF 1 "register_operand")]
15357                    UNSPEC_FIST))
15358    (clobber (match_operand:DI 2 "memory_operand"))
15359    (clobber (match_scratch 3))]
15360   "reload_completed"
15361   [(parallel [(set (match_dup 2) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
15362               (clobber (match_dup 3))])
15363    (set (match_dup 0) (match_dup 2))])
15364
15365 (define_split
15366   [(set (match_operand:DI 0 "memory_operand")
15367         (unspec:DI [(match_operand:XF 1 "register_operand")]
15368                    UNSPEC_FIST))
15369    (clobber (match_operand:DI 2 "memory_operand"))
15370    (clobber (match_scratch 3))]
15371   "reload_completed"
15372   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
15373               (clobber (match_dup 3))])])
15374
15375 (define_insn_and_split "*fist<mode>2_1"
15376   [(set (match_operand:SWI24 0 "register_operand")
15377         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15378                       UNSPEC_FIST))]
15379   "TARGET_USE_FANCY_MATH_387
15380    && can_create_pseudo_p ()"
15381   "#"
15382   "&& 1"
15383   [(const_int 0)]
15384 {
15385   operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
15386   emit_insn (gen_fist<mode>2_with_temp (operands[0], operands[1],
15387                                         operands[2]));
15388   DONE;
15389 }
15390   [(set_attr "type" "fpspc")
15391    (set_attr "mode" "<MODE>")])
15392
15393 (define_insn "fist<mode>2"
15394   [(set (match_operand:SWI24 0 "memory_operand" "=m")
15395         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")]
15396                       UNSPEC_FIST))]
15397   "TARGET_USE_FANCY_MATH_387"
15398   "* return output_fix_trunc (insn, operands, false);"
15399   [(set_attr "type" "fpspc")
15400    (set_attr "mode" "<MODE>")])
15401
15402 (define_insn "fist<mode>2_with_temp"
15403   [(set (match_operand:SWI24 0 "register_operand" "=r")
15404         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")]
15405                       UNSPEC_FIST))
15406    (clobber (match_operand:SWI24 2 "memory_operand" "=m"))]
15407   "TARGET_USE_FANCY_MATH_387"
15408   "#"
15409   [(set_attr "type" "fpspc")
15410    (set_attr "mode" "<MODE>")])
15411
15412 (define_split
15413   [(set (match_operand:SWI24 0 "register_operand")
15414         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15415                       UNSPEC_FIST))
15416    (clobber (match_operand:SWI24 2 "memory_operand"))]
15417   "reload_completed"
15418   [(set (match_dup 2) (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST))
15419    (set (match_dup 0) (match_dup 2))])
15420
15421 (define_split
15422   [(set (match_operand:SWI24 0 "memory_operand")
15423         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15424                       UNSPEC_FIST))
15425    (clobber (match_operand:SWI24 2 "memory_operand"))]
15426   "reload_completed"
15427   [(set (match_dup 0) (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST))])
15428
15429 (define_expand "lrintxf<mode>2"
15430   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
15431      (unspec:SWI248x [(match_operand:XF 1 "register_operand")]
15432                      UNSPEC_FIST))]
15433   "TARGET_USE_FANCY_MATH_387")
15434
15435 (define_expand "lrint<MODEF:mode><SWI48:mode>2"
15436   [(set (match_operand:SWI48 0 "nonimmediate_operand")
15437      (unspec:SWI48 [(match_operand:MODEF 1 "register_operand")]
15438                    UNSPEC_FIX_NOTRUNC))]
15439   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH")
15440
15441 (define_expand "lround<X87MODEF:mode><SWI248x:mode>2"
15442   [(match_operand:SWI248x 0 "nonimmediate_operand")
15443    (match_operand:X87MODEF 1 "register_operand")]
15444   "(TARGET_USE_FANCY_MATH_387
15445     && (!(SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)
15446         || TARGET_MIX_SSE_I387)
15447     && flag_unsafe_math_optimizations)
15448    || (SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH
15449        && <SWI248x:MODE>mode != HImode 
15450        && ((<SWI248x:MODE>mode != DImode) || TARGET_64BIT)
15451        && !flag_trapping_math && !flag_rounding_math)"
15452 {
15453   if (optimize_insn_for_size_p ())
15454     FAIL;
15455
15456   if (SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH
15457       && <SWI248x:MODE>mode != HImode
15458       && ((<SWI248x:MODE>mode != DImode) || TARGET_64BIT)
15459       && !flag_trapping_math && !flag_rounding_math)
15460     ix86_expand_lround (operands[0], operands[1]);
15461   else
15462     ix86_emit_i387_round (operands[0], operands[1]);
15463   DONE;
15464 })
15465
15466 (define_int_iterator FRNDINT_ROUNDING
15467         [UNSPEC_FRNDINT_FLOOR
15468          UNSPEC_FRNDINT_CEIL
15469          UNSPEC_FRNDINT_TRUNC])
15470
15471 (define_int_iterator FIST_ROUNDING
15472         [UNSPEC_FIST_FLOOR
15473          UNSPEC_FIST_CEIL])
15474
15475 ;; Base name for define_insn
15476 (define_int_attr rounding_insn
15477         [(UNSPEC_FRNDINT_FLOOR "floor")
15478          (UNSPEC_FRNDINT_CEIL "ceil")
15479          (UNSPEC_FRNDINT_TRUNC "btrunc")
15480          (UNSPEC_FIST_FLOOR "floor")
15481          (UNSPEC_FIST_CEIL "ceil")])
15482
15483 (define_int_attr rounding
15484         [(UNSPEC_FRNDINT_FLOOR "floor")
15485          (UNSPEC_FRNDINT_CEIL "ceil")
15486          (UNSPEC_FRNDINT_TRUNC "trunc")
15487          (UNSPEC_FIST_FLOOR "floor")
15488          (UNSPEC_FIST_CEIL "ceil")])
15489
15490 (define_int_attr ROUNDING
15491         [(UNSPEC_FRNDINT_FLOOR "FLOOR")
15492          (UNSPEC_FRNDINT_CEIL "CEIL")
15493          (UNSPEC_FRNDINT_TRUNC "TRUNC")
15494          (UNSPEC_FIST_FLOOR "FLOOR")
15495          (UNSPEC_FIST_CEIL "CEIL")])
15496
15497 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15498 (define_insn_and_split "frndintxf2_<rounding>"
15499   [(set (match_operand:XF 0 "register_operand")
15500         (unspec:XF [(match_operand:XF 1 "register_operand")]
15501                    FRNDINT_ROUNDING))
15502    (clobber (reg:CC FLAGS_REG))]
15503   "TARGET_USE_FANCY_MATH_387
15504    && flag_unsafe_math_optimizations
15505    && can_create_pseudo_p ()"
15506   "#"
15507   "&& 1"
15508   [(const_int 0)]
15509 {
15510   ix86_optimize_mode_switching[I387_<ROUNDING>] = 1;
15511
15512   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15513   operands[3] = assign_386_stack_local (HImode, SLOT_CW_<ROUNDING>);
15514
15515   emit_insn (gen_frndintxf2_<rounding>_i387 (operands[0], operands[1],
15516                                              operands[2], operands[3]));
15517   DONE;
15518 }
15519   [(set_attr "type" "frndint")
15520    (set_attr "i387_cw" "<rounding>")
15521    (set_attr "mode" "XF")])
15522
15523 (define_insn "frndintxf2_<rounding>_i387"
15524   [(set (match_operand:XF 0 "register_operand" "=f")
15525         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15526                    FRNDINT_ROUNDING))
15527    (use (match_operand:HI 2 "memory_operand" "m"))
15528    (use (match_operand:HI 3 "memory_operand" "m"))]
15529   "TARGET_USE_FANCY_MATH_387
15530    && flag_unsafe_math_optimizations"
15531   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
15532   [(set_attr "type" "frndint")
15533    (set_attr "i387_cw" "<rounding>")
15534    (set_attr "mode" "XF")])
15535
15536 (define_expand "<rounding_insn>xf2"
15537   [(parallel [(set (match_operand:XF 0 "register_operand")
15538                    (unspec:XF [(match_operand:XF 1 "register_operand")]
15539                               FRNDINT_ROUNDING))
15540               (clobber (reg:CC FLAGS_REG))])]
15541   "TARGET_USE_FANCY_MATH_387
15542    && flag_unsafe_math_optimizations
15543    && !optimize_insn_for_size_p ()")
15544
15545 (define_expand "<rounding_insn><mode>2"
15546   [(parallel [(set (match_operand:MODEF 0 "register_operand")
15547                    (unspec:MODEF [(match_operand:MODEF 1 "register_operand")]
15548                                  FRNDINT_ROUNDING))
15549               (clobber (reg:CC FLAGS_REG))])]
15550   "(TARGET_USE_FANCY_MATH_387
15551     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15552         || TARGET_MIX_SSE_I387)
15553     && flag_unsafe_math_optimizations)
15554    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15555        && !flag_trapping_math)"
15556 {
15557   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15558       && !flag_trapping_math)
15559     {
15560       if (TARGET_ROUND)
15561         emit_insn (gen_sse4_1_round<mode>2
15562                    (operands[0], operands[1], GEN_INT (ROUND_<ROUNDING>)));
15563       else if (optimize_insn_for_size_p ())
15564         FAIL;
15565       else if (TARGET_64BIT || (<MODE>mode != DFmode))
15566         {
15567           if (ROUND_<ROUNDING> == ROUND_FLOOR)
15568             ix86_expand_floorceil (operands[0], operands[1], true);
15569           else if (ROUND_<ROUNDING> == ROUND_CEIL)
15570             ix86_expand_floorceil (operands[0], operands[1], false);
15571           else if (ROUND_<ROUNDING> == ROUND_TRUNC)
15572             ix86_expand_trunc (operands[0], operands[1]);
15573           else
15574             gcc_unreachable ();
15575         }
15576       else
15577         {
15578           if (ROUND_<ROUNDING> == ROUND_FLOOR)
15579             ix86_expand_floorceildf_32 (operands[0], operands[1], true);
15580           else if (ROUND_<ROUNDING> == ROUND_CEIL)
15581             ix86_expand_floorceildf_32 (operands[0], operands[1], false);
15582           else if (ROUND_<ROUNDING> == ROUND_TRUNC)
15583             ix86_expand_truncdf_32 (operands[0], operands[1]);
15584           else
15585             gcc_unreachable ();
15586         }
15587     }
15588   else
15589     {
15590       rtx op0, op1;
15591
15592       if (optimize_insn_for_size_p ())
15593         FAIL;
15594
15595       op0 = gen_reg_rtx (XFmode);
15596       op1 = gen_reg_rtx (XFmode);
15597       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15598       emit_insn (gen_frndintxf2_<rounding> (op0, op1));
15599
15600       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15601     }
15602   DONE;
15603 })
15604
15605 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15606 (define_insn_and_split "frndintxf2_mask_pm"
15607   [(set (match_operand:XF 0 "register_operand")
15608         (unspec:XF [(match_operand:XF 1 "register_operand")]
15609                    UNSPEC_FRNDINT_MASK_PM))
15610    (clobber (reg:CC FLAGS_REG))]
15611   "TARGET_USE_FANCY_MATH_387
15612    && flag_unsafe_math_optimizations
15613    && can_create_pseudo_p ()"
15614   "#"
15615   "&& 1"
15616   [(const_int 0)]
15617 {
15618   ix86_optimize_mode_switching[I387_MASK_PM] = 1;
15619
15620   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15621   operands[3] = assign_386_stack_local (HImode, SLOT_CW_MASK_PM);
15622
15623   emit_insn (gen_frndintxf2_mask_pm_i387 (operands[0], operands[1],
15624                                           operands[2], operands[3]));
15625   DONE;
15626 }
15627   [(set_attr "type" "frndint")
15628    (set_attr "i387_cw" "mask_pm")
15629    (set_attr "mode" "XF")])
15630
15631 (define_insn "frndintxf2_mask_pm_i387"
15632   [(set (match_operand:XF 0 "register_operand" "=f")
15633         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15634                    UNSPEC_FRNDINT_MASK_PM))
15635    (use (match_operand:HI 2 "memory_operand" "m"))
15636    (use (match_operand:HI 3 "memory_operand" "m"))]
15637   "TARGET_USE_FANCY_MATH_387
15638    && flag_unsafe_math_optimizations"
15639   "fldcw\t%3\n\tfrndint\n\tfclex\n\tfldcw\t%2"
15640   [(set_attr "type" "frndint")
15641    (set_attr "i387_cw" "mask_pm")
15642    (set_attr "mode" "XF")])
15643
15644 (define_expand "nearbyintxf2"
15645   [(parallel [(set (match_operand:XF 0 "register_operand")
15646                    (unspec:XF [(match_operand:XF 1 "register_operand")]
15647                               UNSPEC_FRNDINT_MASK_PM))
15648               (clobber (reg:CC FLAGS_REG))])]
15649   "TARGET_USE_FANCY_MATH_387
15650    && flag_unsafe_math_optimizations")
15651
15652 (define_expand "nearbyint<mode>2"
15653   [(use (match_operand:MODEF 0 "register_operand"))
15654    (use (match_operand:MODEF 1 "register_operand"))]
15655   "TARGET_USE_FANCY_MATH_387
15656    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15657        || TARGET_MIX_SSE_I387)
15658    && flag_unsafe_math_optimizations"
15659 {
15660   rtx op0 = gen_reg_rtx (XFmode);
15661   rtx op1 = gen_reg_rtx (XFmode);
15662
15663   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15664   emit_insn (gen_frndintxf2_mask_pm (op0, op1));
15665
15666   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15667   DONE;
15668 })
15669
15670 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15671 (define_insn_and_split "*fist<mode>2_<rounding>_1"
15672   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
15673         (unspec:SWI248x [(match_operand:XF 1 "register_operand")]
15674                         FIST_ROUNDING))
15675    (clobber (reg:CC FLAGS_REG))]
15676   "TARGET_USE_FANCY_MATH_387
15677    && flag_unsafe_math_optimizations
15678    && can_create_pseudo_p ()"
15679   "#"
15680   "&& 1"
15681   [(const_int 0)]
15682 {
15683   ix86_optimize_mode_switching[I387_<ROUNDING>] = 1;
15684
15685   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15686   operands[3] = assign_386_stack_local (HImode, SLOT_CW_<ROUNDING>);
15687   if (memory_operand (operands[0], VOIDmode))
15688     emit_insn (gen_fist<mode>2_<rounding> (operands[0], operands[1],
15689                                            operands[2], operands[3]));
15690   else
15691     {
15692       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
15693       emit_insn (gen_fist<mode>2_<rounding>_with_temp
15694                   (operands[0], operands[1], operands[2],
15695                    operands[3], operands[4]));
15696     }
15697   DONE;
15698 }
15699   [(set_attr "type" "fistp")
15700    (set_attr "i387_cw" "<rounding>")
15701    (set_attr "mode" "<MODE>")])
15702
15703 (define_insn "fistdi2_<rounding>"
15704   [(set (match_operand:DI 0 "memory_operand" "=m")
15705         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
15706                    FIST_ROUNDING))
15707    (use (match_operand:HI 2 "memory_operand" "m"))
15708    (use (match_operand:HI 3 "memory_operand" "m"))
15709    (clobber (match_scratch:XF 4 "=&1f"))]
15710   "TARGET_USE_FANCY_MATH_387
15711    && flag_unsafe_math_optimizations"
15712   "* return output_fix_trunc (insn, operands, false);"
15713   [(set_attr "type" "fistp")
15714    (set_attr "i387_cw" "<rounding>")
15715    (set_attr "mode" "DI")])
15716
15717 (define_insn "fistdi2_<rounding>_with_temp"
15718   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
15719         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
15720                    FIST_ROUNDING))
15721    (use (match_operand:HI 2 "memory_operand" "m,m"))
15722    (use (match_operand:HI 3 "memory_operand" "m,m"))
15723    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
15724    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
15725   "TARGET_USE_FANCY_MATH_387
15726    && flag_unsafe_math_optimizations"
15727   "#"
15728   [(set_attr "type" "fistp")
15729    (set_attr "i387_cw" "<rounding>")
15730    (set_attr "mode" "DI")])
15731
15732 (define_split
15733   [(set (match_operand:DI 0 "register_operand")
15734         (unspec:DI [(match_operand:XF 1 "register_operand")]
15735                    FIST_ROUNDING))
15736    (use (match_operand:HI 2 "memory_operand"))
15737    (use (match_operand:HI 3 "memory_operand"))
15738    (clobber (match_operand:DI 4 "memory_operand"))
15739    (clobber (match_scratch 5))]
15740   "reload_completed"
15741   [(parallel [(set (match_dup 4)
15742                    (unspec:DI [(match_dup 1)] FIST_ROUNDING))
15743               (use (match_dup 2))
15744               (use (match_dup 3))
15745               (clobber (match_dup 5))])
15746    (set (match_dup 0) (match_dup 4))])
15747
15748 (define_split
15749   [(set (match_operand:DI 0 "memory_operand")
15750         (unspec:DI [(match_operand:XF 1 "register_operand")]
15751                    FIST_ROUNDING))
15752    (use (match_operand:HI 2 "memory_operand"))
15753    (use (match_operand:HI 3 "memory_operand"))
15754    (clobber (match_operand:DI 4 "memory_operand"))
15755    (clobber (match_scratch 5))]
15756   "reload_completed"
15757   [(parallel [(set (match_dup 0)
15758                    (unspec:DI [(match_dup 1)] FIST_ROUNDING))
15759               (use (match_dup 2))
15760               (use (match_dup 3))
15761               (clobber (match_dup 5))])])
15762
15763 (define_insn "fist<mode>2_<rounding>"
15764   [(set (match_operand:SWI24 0 "memory_operand" "=m")
15765         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")]
15766                       FIST_ROUNDING))
15767    (use (match_operand:HI 2 "memory_operand" "m"))
15768    (use (match_operand:HI 3 "memory_operand" "m"))]
15769   "TARGET_USE_FANCY_MATH_387
15770    && flag_unsafe_math_optimizations"
15771   "* return output_fix_trunc (insn, operands, false);"
15772   [(set_attr "type" "fistp")
15773    (set_attr "i387_cw" "<rounding>")
15774    (set_attr "mode" "<MODE>")])
15775
15776 (define_insn "fist<mode>2_<rounding>_with_temp"
15777   [(set (match_operand:SWI24 0 "nonimmediate_operand" "=m,?r")
15778         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f,f")]
15779                       FIST_ROUNDING))
15780    (use (match_operand:HI 2 "memory_operand" "m,m"))
15781    (use (match_operand:HI 3 "memory_operand" "m,m"))
15782    (clobber (match_operand:SWI24 4 "memory_operand" "=X,m"))]
15783   "TARGET_USE_FANCY_MATH_387
15784    && flag_unsafe_math_optimizations"
15785   "#"
15786   [(set_attr "type" "fistp")
15787    (set_attr "i387_cw" "<rounding>")
15788    (set_attr "mode" "<MODE>")])
15789
15790 (define_split
15791   [(set (match_operand:SWI24 0 "register_operand")
15792         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15793                       FIST_ROUNDING))
15794    (use (match_operand:HI 2 "memory_operand"))
15795    (use (match_operand:HI 3 "memory_operand"))
15796    (clobber (match_operand:SWI24 4 "memory_operand"))]
15797   "reload_completed"
15798   [(parallel [(set (match_dup 4)
15799                    (unspec:SWI24 [(match_dup 1)] FIST_ROUNDING))
15800               (use (match_dup 2))
15801               (use (match_dup 3))])
15802    (set (match_dup 0) (match_dup 4))])
15803
15804 (define_split
15805   [(set (match_operand:SWI24 0 "memory_operand")
15806         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15807                       FIST_ROUNDING))
15808    (use (match_operand:HI 2 "memory_operand"))
15809    (use (match_operand:HI 3 "memory_operand"))
15810    (clobber (match_operand:SWI24 4 "memory_operand"))]
15811   "reload_completed"
15812   [(parallel [(set (match_dup 0)
15813                    (unspec:SWI24 [(match_dup 1)] FIST_ROUNDING))
15814               (use (match_dup 2))
15815               (use (match_dup 3))])])
15816
15817 (define_expand "l<rounding_insn>xf<mode>2"
15818   [(parallel [(set (match_operand:SWI248x 0 "nonimmediate_operand")
15819                    (unspec:SWI248x [(match_operand:XF 1 "register_operand")]
15820                                    FIST_ROUNDING))
15821               (clobber (reg:CC FLAGS_REG))])]
15822   "TARGET_USE_FANCY_MATH_387
15823    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
15824    && flag_unsafe_math_optimizations")
15825
15826 (define_expand "l<rounding_insn><MODEF:mode><SWI48:mode>2"
15827   [(parallel [(set (match_operand:SWI48 0 "nonimmediate_operand")
15828                    (unspec:SWI48 [(match_operand:MODEF 1 "register_operand")]
15829                                  FIST_ROUNDING))
15830               (clobber (reg:CC FLAGS_REG))])]
15831   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
15832    && !flag_trapping_math"
15833 {
15834   if (TARGET_64BIT && optimize_insn_for_size_p ())
15835     FAIL;
15836
15837   if (ROUND_<ROUNDING> == ROUND_FLOOR)
15838     ix86_expand_lfloorceil (operands[0], operands[1], true);
15839   else if (ROUND_<ROUNDING> == ROUND_CEIL)
15840     ix86_expand_lfloorceil (operands[0], operands[1], false);
15841   else
15842     gcc_unreachable ();
15843
15844   DONE;
15845 })
15846
15847 (define_insn "fxam<mode>2_i387"
15848   [(set (match_operand:HI 0 "register_operand" "=a")
15849         (unspec:HI
15850           [(match_operand:X87MODEF 1 "register_operand" "f")]
15851           UNSPEC_FXAM))]
15852   "TARGET_USE_FANCY_MATH_387"
15853   "fxam\n\tfnstsw\t%0"
15854   [(set_attr "type" "multi")
15855    (set_attr "length" "4")
15856    (set_attr "unit" "i387")
15857    (set_attr "mode" "<MODE>")])
15858
15859 (define_insn_and_split "fxam<mode>2_i387_with_temp"
15860   [(set (match_operand:HI 0 "register_operand")
15861         (unspec:HI
15862           [(match_operand:MODEF 1 "memory_operand")]
15863           UNSPEC_FXAM_MEM))]
15864   "TARGET_USE_FANCY_MATH_387
15865    && can_create_pseudo_p ()"
15866   "#"
15867   "&& 1"
15868   [(set (match_dup 2)(match_dup 1))
15869    (set (match_dup 0)
15870         (unspec:HI [(match_dup 2)] UNSPEC_FXAM))]
15871 {
15872   operands[2] = gen_reg_rtx (<MODE>mode);
15873
15874   MEM_VOLATILE_P (operands[1]) = 1;
15875 }
15876   [(set_attr "type" "multi")
15877    (set_attr "unit" "i387")
15878    (set_attr "mode" "<MODE>")])
15879
15880 (define_expand "isinfxf2"
15881   [(use (match_operand:SI 0 "register_operand"))
15882    (use (match_operand:XF 1 "register_operand"))]
15883   "TARGET_USE_FANCY_MATH_387
15884    && ix86_libc_has_function (function_c99_misc)"
15885 {
15886   rtx mask = GEN_INT (0x45);
15887   rtx val = GEN_INT (0x05);
15888
15889   rtx cond;
15890
15891   rtx scratch = gen_reg_rtx (HImode);
15892   rtx res = gen_reg_rtx (QImode);
15893
15894   emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
15895
15896   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
15897   emit_insn (gen_cmpqi_ext_3 (scratch, val));
15898   cond = gen_rtx_fmt_ee (EQ, QImode,
15899                          gen_rtx_REG (CCmode, FLAGS_REG),
15900                          const0_rtx);
15901   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
15902   emit_insn (gen_zero_extendqisi2 (operands[0], res));
15903   DONE;
15904 })
15905
15906 (define_expand "isinf<mode>2"
15907   [(use (match_operand:SI 0 "register_operand"))
15908    (use (match_operand:MODEF 1 "nonimmediate_operand"))]
15909   "TARGET_USE_FANCY_MATH_387
15910    && ix86_libc_has_function (function_c99_misc)
15911    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
15912 {
15913   rtx mask = GEN_INT (0x45);
15914   rtx val = GEN_INT (0x05);
15915
15916   rtx cond;
15917
15918   rtx scratch = gen_reg_rtx (HImode);
15919   rtx res = gen_reg_rtx (QImode);
15920
15921   /* Remove excess precision by forcing value through memory. */
15922   if (memory_operand (operands[1], VOIDmode))
15923     emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, operands[1]));
15924   else
15925     {
15926       rtx temp = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
15927
15928       emit_move_insn (temp, operands[1]);
15929       emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, temp));
15930     }
15931
15932   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
15933   emit_insn (gen_cmpqi_ext_3 (scratch, val));
15934   cond = gen_rtx_fmt_ee (EQ, QImode,
15935                          gen_rtx_REG (CCmode, FLAGS_REG),
15936                          const0_rtx);
15937   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
15938   emit_insn (gen_zero_extendqisi2 (operands[0], res));
15939   DONE;
15940 })
15941
15942 (define_expand "signbitxf2"
15943   [(use (match_operand:SI 0 "register_operand"))
15944    (use (match_operand:XF 1 "register_operand"))]
15945   "TARGET_USE_FANCY_MATH_387"
15946 {
15947   rtx scratch = gen_reg_rtx (HImode);
15948
15949   emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
15950   emit_insn (gen_andsi3 (operands[0],
15951              gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15952   DONE;
15953 })
15954
15955 (define_insn "movmsk_df"
15956   [(set (match_operand:SI 0 "register_operand" "=r")
15957         (unspec:SI
15958           [(match_operand:DF 1 "register_operand" "x")]
15959           UNSPEC_MOVMSK))]
15960   "SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH"
15961   "%vmovmskpd\t{%1, %0|%0, %1}"
15962   [(set_attr "type" "ssemov")
15963    (set_attr "prefix" "maybe_vex")
15964    (set_attr "mode" "DF")])
15965
15966 ;; Use movmskpd in SSE mode to avoid store forwarding stall
15967 ;; for 32bit targets and movq+shrq sequence for 64bit targets.
15968 (define_expand "signbitdf2"
15969   [(use (match_operand:SI 0 "register_operand"))
15970    (use (match_operand:DF 1 "register_operand"))]
15971   "TARGET_USE_FANCY_MATH_387
15972    || (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)"
15973 {
15974   if (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)
15975     {
15976       emit_insn (gen_movmsk_df (operands[0], operands[1]));
15977       emit_insn (gen_andsi3 (operands[0], operands[0], const1_rtx));
15978     }
15979   else
15980     {
15981       rtx scratch = gen_reg_rtx (HImode);
15982
15983       emit_insn (gen_fxamdf2_i387 (scratch, operands[1]));
15984       emit_insn (gen_andsi3 (operands[0],
15985                  gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15986     }
15987   DONE;
15988 })
15989
15990 (define_expand "signbitsf2"
15991   [(use (match_operand:SI 0 "register_operand"))
15992    (use (match_operand:SF 1 "register_operand"))]
15993   "TARGET_USE_FANCY_MATH_387
15994    && !(SSE_FLOAT_MODE_P (SFmode) && TARGET_SSE_MATH)"
15995 {
15996   rtx scratch = gen_reg_rtx (HImode);
15997
15998   emit_insn (gen_fxamsf2_i387 (scratch, operands[1]));
15999   emit_insn (gen_andsi3 (operands[0],
16000              gen_lowpart (SImode, scratch), GEN_INT (0x200)));
16001   DONE;
16002 })
16003 \f
16004 ;; Block operation instructions
16005
16006 (define_insn "cld"
16007   [(unspec_volatile [(const_int 0)] UNSPECV_CLD)]
16008   ""
16009   "cld"
16010   [(set_attr "length" "1")
16011    (set_attr "length_immediate" "0")
16012    (set_attr "modrm" "0")])
16013
16014 (define_expand "movmem<mode>"
16015   [(use (match_operand:BLK 0 "memory_operand"))
16016    (use (match_operand:BLK 1 "memory_operand"))
16017    (use (match_operand:SWI48 2 "nonmemory_operand"))
16018    (use (match_operand:SWI48 3 "const_int_operand"))
16019    (use (match_operand:SI 4 "const_int_operand"))
16020    (use (match_operand:SI 5 "const_int_operand"))
16021    (use (match_operand:SI 6 ""))
16022    (use (match_operand:SI 7 ""))
16023    (use (match_operand:SI 8 ""))]
16024   ""
16025 {
16026  if (ix86_expand_set_or_movmem (operands[0], operands[1],
16027                                 operands[2], NULL, operands[3],
16028                                 operands[4], operands[5],
16029                                 operands[6], operands[7],
16030                                 operands[8], false))
16031    DONE;
16032  else
16033    FAIL;
16034 })
16035
16036 ;; Most CPUs don't like single string operations
16037 ;; Handle this case here to simplify previous expander.
16038
16039 (define_expand "strmov"
16040   [(set (match_dup 4) (match_operand 3 "memory_operand"))
16041    (set (match_operand 1 "memory_operand") (match_dup 4))
16042    (parallel [(set (match_operand 0 "register_operand") (match_dup 5))
16043               (clobber (reg:CC FLAGS_REG))])
16044    (parallel [(set (match_operand 2 "register_operand") (match_dup 6))
16045               (clobber (reg:CC FLAGS_REG))])]
16046   ""
16047 {
16048   rtx adjust = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[1])));
16049
16050   /* If .md ever supports :P for Pmode, these can be directly
16051      in the pattern above.  */
16052   operands[5] = gen_rtx_PLUS (Pmode, operands[0], adjust);
16053   operands[6] = gen_rtx_PLUS (Pmode, operands[2], adjust);
16054
16055   /* Can't use this if the user has appropriated esi or edi.  */
16056   if ((TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
16057       && !(fixed_regs[SI_REG] || fixed_regs[DI_REG]))
16058     {
16059       emit_insn (gen_strmov_singleop (operands[0], operands[1],
16060                                       operands[2], operands[3],
16061                                       operands[5], operands[6]));
16062       DONE;
16063     }
16064
16065   operands[4] = gen_reg_rtx (GET_MODE (operands[1]));
16066 })
16067
16068 (define_expand "strmov_singleop"
16069   [(parallel [(set (match_operand 1 "memory_operand")
16070                    (match_operand 3 "memory_operand"))
16071               (set (match_operand 0 "register_operand")
16072                    (match_operand 4))
16073               (set (match_operand 2 "register_operand")
16074                    (match_operand 5))])]
16075   ""
16076   "ix86_current_function_needs_cld = 1;")
16077
16078 (define_insn "*strmovdi_rex_1"
16079   [(set (mem:DI (match_operand:P 2 "register_operand" "0"))
16080         (mem:DI (match_operand:P 3 "register_operand" "1")))
16081    (set (match_operand:P 0 "register_operand" "=D")
16082         (plus:P (match_dup 2)
16083                 (const_int 8)))
16084    (set (match_operand:P 1 "register_operand" "=S")
16085         (plus:P (match_dup 3)
16086                 (const_int 8)))]
16087   "TARGET_64BIT
16088    && !(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16089   "%^movsq"
16090   [(set_attr "type" "str")
16091    (set_attr "memory" "both")
16092    (set_attr "mode" "DI")])
16093
16094 (define_insn "*strmovsi_1"
16095   [(set (mem:SI (match_operand:P 2 "register_operand" "0"))
16096         (mem:SI (match_operand:P 3 "register_operand" "1")))
16097    (set (match_operand:P 0 "register_operand" "=D")
16098         (plus:P (match_dup 2)
16099                 (const_int 4)))
16100    (set (match_operand:P 1 "register_operand" "=S")
16101         (plus:P (match_dup 3)
16102                 (const_int 4)))]
16103   "!(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16104   "%^movs{l|d}"
16105   [(set_attr "type" "str")
16106    (set_attr "memory" "both")
16107    (set_attr "mode" "SI")])
16108
16109 (define_insn "*strmovhi_1"
16110   [(set (mem:HI (match_operand:P 2 "register_operand" "0"))
16111         (mem:HI (match_operand:P 3 "register_operand" "1")))
16112    (set (match_operand:P 0 "register_operand" "=D")
16113         (plus:P (match_dup 2)
16114                 (const_int 2)))
16115    (set (match_operand:P 1 "register_operand" "=S")
16116         (plus:P (match_dup 3)
16117                 (const_int 2)))]
16118   "!(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16119   "%^movsw"
16120   [(set_attr "type" "str")
16121    (set_attr "memory" "both")
16122    (set_attr "mode" "HI")])
16123
16124 (define_insn "*strmovqi_1"
16125   [(set (mem:QI (match_operand:P 2 "register_operand" "0"))
16126         (mem:QI (match_operand:P 3 "register_operand" "1")))
16127    (set (match_operand:P 0 "register_operand" "=D")
16128         (plus:P (match_dup 2)
16129                 (const_int 1)))
16130    (set (match_operand:P 1 "register_operand" "=S")
16131         (plus:P (match_dup 3)
16132                 (const_int 1)))]
16133   "!(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16134   "%^movsb"
16135   [(set_attr "type" "str")
16136    (set_attr "memory" "both")
16137    (set (attr "prefix_rex")
16138         (if_then_else
16139           (match_test "<P:MODE>mode == DImode")
16140           (const_string "0")
16141           (const_string "*")))
16142    (set_attr "mode" "QI")])
16143
16144 (define_expand "rep_mov"
16145   [(parallel [(set (match_operand 4 "register_operand") (const_int 0))
16146               (set (match_operand 0 "register_operand")
16147                    (match_operand 5))
16148               (set (match_operand 2 "register_operand")
16149                    (match_operand 6))
16150               (set (match_operand 1 "memory_operand")
16151                    (match_operand 3 "memory_operand"))
16152               (use (match_dup 4))])]
16153   ""
16154   "ix86_current_function_needs_cld = 1;")
16155
16156 (define_insn "*rep_movdi_rex64"
16157   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
16158    (set (match_operand:P 0 "register_operand" "=D")
16159         (plus:P (ashift:P (match_operand:P 5 "register_operand" "2")
16160                           (const_int 3))
16161                 (match_operand:P 3 "register_operand" "0")))
16162    (set (match_operand:P 1 "register_operand" "=S")
16163         (plus:P (ashift:P (match_dup 5) (const_int 3))
16164                 (match_operand:P 4 "register_operand" "1")))
16165    (set (mem:BLK (match_dup 3))
16166         (mem:BLK (match_dup 4)))
16167    (use (match_dup 5))]
16168   "TARGET_64BIT
16169    && !(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16170   "%^rep{%;} movsq"
16171   [(set_attr "type" "str")
16172    (set_attr "prefix_rep" "1")
16173    (set_attr "memory" "both")
16174    (set_attr "mode" "DI")])
16175
16176 (define_insn "*rep_movsi"
16177   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
16178    (set (match_operand:P 0 "register_operand" "=D")
16179         (plus:P (ashift:P (match_operand:P 5 "register_operand" "2")
16180                           (const_int 2))
16181                  (match_operand:P 3 "register_operand" "0")))
16182    (set (match_operand:P 1 "register_operand" "=S")
16183         (plus:P (ashift:P (match_dup 5) (const_int 2))
16184                 (match_operand:P 4 "register_operand" "1")))
16185    (set (mem:BLK (match_dup 3))
16186         (mem:BLK (match_dup 4)))
16187    (use (match_dup 5))]
16188   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16189   "%^rep{%;} movs{l|d}"
16190   [(set_attr "type" "str")
16191    (set_attr "prefix_rep" "1")
16192    (set_attr "memory" "both")
16193    (set_attr "mode" "SI")])
16194
16195 (define_insn "*rep_movqi"
16196   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
16197    (set (match_operand:P 0 "register_operand" "=D")
16198         (plus:P (match_operand:P 3 "register_operand" "0")
16199                 (match_operand:P 5 "register_operand" "2")))
16200    (set (match_operand:P 1 "register_operand" "=S")
16201         (plus:P (match_operand:P 4 "register_operand" "1") (match_dup 5)))
16202    (set (mem:BLK (match_dup 3))
16203         (mem:BLK (match_dup 4)))
16204    (use (match_dup 5))]
16205   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16206   "%^rep{%;} movsb"
16207   [(set_attr "type" "str")
16208    (set_attr "prefix_rep" "1")
16209    (set_attr "memory" "both")
16210    (set_attr "mode" "QI")])
16211
16212 (define_expand "setmem<mode>"
16213    [(use (match_operand:BLK 0 "memory_operand"))
16214     (use (match_operand:SWI48 1 "nonmemory_operand"))
16215     (use (match_operand:QI 2 "nonmemory_operand"))
16216     (use (match_operand 3 "const_int_operand"))
16217     (use (match_operand:SI 4 "const_int_operand"))
16218     (use (match_operand:SI 5 "const_int_operand"))
16219     (use (match_operand:SI 6 ""))
16220     (use (match_operand:SI 7 ""))
16221     (use (match_operand:SI 8 ""))]
16222   ""
16223 {
16224  if (ix86_expand_set_or_movmem (operands[0], NULL,
16225                                 operands[1], operands[2],
16226                                 operands[3], operands[4],
16227                                 operands[5], operands[6],
16228                                 operands[7], operands[8], true))
16229    DONE;
16230  else
16231    FAIL;
16232 })
16233
16234 ;; Most CPUs don't like single string operations
16235 ;; Handle this case here to simplify previous expander.
16236
16237 (define_expand "strset"
16238   [(set (match_operand 1 "memory_operand")
16239         (match_operand 2 "register_operand"))
16240    (parallel [(set (match_operand 0 "register_operand")
16241                    (match_dup 3))
16242               (clobber (reg:CC FLAGS_REG))])]
16243   ""
16244 {
16245   if (GET_MODE (operands[1]) != GET_MODE (operands[2]))
16246     operands[1] = adjust_address_nv (operands[1], GET_MODE (operands[2]), 0);
16247
16248   /* If .md ever supports :P for Pmode, this can be directly
16249      in the pattern above.  */
16250   operands[3] = gen_rtx_PLUS (Pmode, operands[0],
16251                               GEN_INT (GET_MODE_SIZE (GET_MODE
16252                                                       (operands[2]))));
16253   /* Can't use this if the user has appropriated eax or edi.  */
16254   if ((TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
16255       && !(fixed_regs[AX_REG] || fixed_regs[DI_REG]))
16256     {
16257       emit_insn (gen_strset_singleop (operands[0], operands[1], operands[2],
16258                                       operands[3]));
16259       DONE;
16260     }
16261 })
16262
16263 (define_expand "strset_singleop"
16264   [(parallel [(set (match_operand 1 "memory_operand")
16265                    (match_operand 2 "register_operand"))
16266               (set (match_operand 0 "register_operand")
16267                    (match_operand 3))
16268               (unspec [(const_int 0)] UNSPEC_STOS)])]
16269   ""
16270   "ix86_current_function_needs_cld = 1;")
16271
16272 (define_insn "*strsetdi_rex_1"
16273   [(set (mem:DI (match_operand:P 1 "register_operand" "0"))
16274         (match_operand:DI 2 "register_operand" "a"))
16275    (set (match_operand:P 0 "register_operand" "=D")
16276         (plus:P (match_dup 1)
16277                 (const_int 8)))
16278    (unspec [(const_int 0)] UNSPEC_STOS)]
16279   "TARGET_64BIT
16280    && !(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16281   "%^stosq"
16282   [(set_attr "type" "str")
16283    (set_attr "memory" "store")
16284    (set_attr "mode" "DI")])
16285
16286 (define_insn "*strsetsi_1"
16287   [(set (mem:SI (match_operand:P 1 "register_operand" "0"))
16288         (match_operand:SI 2 "register_operand" "a"))
16289    (set (match_operand:P 0 "register_operand" "=D")
16290         (plus:P (match_dup 1)
16291                 (const_int 4)))
16292    (unspec [(const_int 0)] UNSPEC_STOS)]
16293   "!(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16294   "%^stos{l|d}"
16295   [(set_attr "type" "str")
16296    (set_attr "memory" "store")
16297    (set_attr "mode" "SI")])
16298
16299 (define_insn "*strsethi_1"
16300   [(set (mem:HI (match_operand:P 1 "register_operand" "0"))
16301         (match_operand:HI 2 "register_operand" "a"))
16302    (set (match_operand:P 0 "register_operand" "=D")
16303         (plus:P (match_dup 1)
16304                 (const_int 2)))
16305    (unspec [(const_int 0)] UNSPEC_STOS)]
16306   "!(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16307   "%^stosw"
16308   [(set_attr "type" "str")
16309    (set_attr "memory" "store")
16310    (set_attr "mode" "HI")])
16311
16312 (define_insn "*strsetqi_1"
16313   [(set (mem:QI (match_operand:P 1 "register_operand" "0"))
16314         (match_operand:QI 2 "register_operand" "a"))
16315    (set (match_operand:P 0 "register_operand" "=D")
16316         (plus:P (match_dup 1)
16317                 (const_int 1)))
16318    (unspec [(const_int 0)] UNSPEC_STOS)]
16319   "!(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16320   "%^stosb"
16321   [(set_attr "type" "str")
16322    (set_attr "memory" "store")
16323    (set (attr "prefix_rex")
16324         (if_then_else
16325           (match_test "<P:MODE>mode == DImode")
16326           (const_string "0")
16327           (const_string "*")))
16328    (set_attr "mode" "QI")])
16329
16330 (define_expand "rep_stos"
16331   [(parallel [(set (match_operand 1 "register_operand") (const_int 0))
16332               (set (match_operand 0 "register_operand")
16333                    (match_operand 4))
16334               (set (match_operand 2 "memory_operand") (const_int 0))
16335               (use (match_operand 3 "register_operand"))
16336               (use (match_dup 1))])]
16337   ""
16338   "ix86_current_function_needs_cld = 1;")
16339
16340 (define_insn "*rep_stosdi_rex64"
16341   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
16342    (set (match_operand:P 0 "register_operand" "=D")
16343         (plus:P (ashift:P (match_operand:P 4 "register_operand" "1")
16344                           (const_int 3))
16345                  (match_operand:P 3 "register_operand" "0")))
16346    (set (mem:BLK (match_dup 3))
16347         (const_int 0))
16348    (use (match_operand:DI 2 "register_operand" "a"))
16349    (use (match_dup 4))]
16350   "TARGET_64BIT
16351    && !(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16352   "%^rep{%;} stosq"
16353   [(set_attr "type" "str")
16354    (set_attr "prefix_rep" "1")
16355    (set_attr "memory" "store")
16356    (set_attr "mode" "DI")])
16357
16358 (define_insn "*rep_stossi"
16359   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
16360    (set (match_operand:P 0 "register_operand" "=D")
16361         (plus:P (ashift:P (match_operand:P 4 "register_operand" "1")
16362                           (const_int 2))
16363                  (match_operand:P 3 "register_operand" "0")))
16364    (set (mem:BLK (match_dup 3))
16365         (const_int 0))
16366    (use (match_operand:SI 2 "register_operand" "a"))
16367    (use (match_dup 4))]
16368   "!(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16369   "%^rep{%;} stos{l|d}"
16370   [(set_attr "type" "str")
16371    (set_attr "prefix_rep" "1")
16372    (set_attr "memory" "store")
16373    (set_attr "mode" "SI")])
16374
16375 (define_insn "*rep_stosqi"
16376   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
16377    (set (match_operand:P 0 "register_operand" "=D")
16378         (plus:P (match_operand:P 3 "register_operand" "0")
16379                 (match_operand:P 4 "register_operand" "1")))
16380    (set (mem:BLK (match_dup 3))
16381         (const_int 0))
16382    (use (match_operand:QI 2 "register_operand" "a"))
16383    (use (match_dup 4))]
16384   "!(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16385   "%^rep{%;} stosb"
16386   [(set_attr "type" "str")
16387    (set_attr "prefix_rep" "1")
16388    (set_attr "memory" "store")
16389    (set (attr "prefix_rex")
16390         (if_then_else
16391           (match_test "<P:MODE>mode == DImode")
16392           (const_string "0")
16393           (const_string "*")))
16394    (set_attr "mode" "QI")])
16395
16396 (define_expand "cmpstrnsi"
16397   [(set (match_operand:SI 0 "register_operand")
16398         (compare:SI (match_operand:BLK 1 "general_operand")
16399                     (match_operand:BLK 2 "general_operand")))
16400    (use (match_operand 3 "general_operand"))
16401    (use (match_operand 4 "immediate_operand"))]
16402   ""
16403 {
16404   rtx addr1, addr2, out, outlow, count, countreg, align;
16405
16406   if (optimize_insn_for_size_p () && !TARGET_INLINE_ALL_STRINGOPS)
16407     FAIL;
16408
16409   /* Can't use this if the user has appropriated ecx, esi or edi.  */
16410   if (fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])
16411     FAIL;
16412
16413   out = operands[0];
16414   if (!REG_P (out))
16415     out = gen_reg_rtx (SImode);
16416
16417   addr1 = copy_addr_to_reg (XEXP (operands[1], 0));
16418   addr2 = copy_addr_to_reg (XEXP (operands[2], 0));
16419   if (addr1 != XEXP (operands[1], 0))
16420     operands[1] = replace_equiv_address_nv (operands[1], addr1);
16421   if (addr2 != XEXP (operands[2], 0))
16422     operands[2] = replace_equiv_address_nv (operands[2], addr2);
16423
16424   count = operands[3];
16425   countreg = ix86_zero_extend_to_Pmode (count);
16426
16427   /* %%% Iff we are testing strict equality, we can use known alignment
16428      to good advantage.  This may be possible with combine, particularly
16429      once cc0 is dead.  */
16430   align = operands[4];
16431
16432   if (CONST_INT_P (count))
16433     {
16434       if (INTVAL (count) == 0)
16435         {
16436           emit_move_insn (operands[0], const0_rtx);
16437           DONE;
16438         }
16439       emit_insn (gen_cmpstrnqi_nz_1 (addr1, addr2, countreg, align,
16440                                      operands[1], operands[2]));
16441     }
16442   else
16443     {
16444       rtx (*gen_cmp) (rtx, rtx);
16445
16446       gen_cmp = (TARGET_64BIT
16447                  ? gen_cmpdi_1 : gen_cmpsi_1);
16448
16449       emit_insn (gen_cmp (countreg, countreg));
16450       emit_insn (gen_cmpstrnqi_1 (addr1, addr2, countreg, align,
16451                                   operands[1], operands[2]));
16452     }
16453
16454   outlow = gen_lowpart (QImode, out);
16455   emit_insn (gen_cmpintqi (outlow));
16456   emit_move_insn (out, gen_rtx_SIGN_EXTEND (SImode, outlow));
16457
16458   if (operands[0] != out)
16459     emit_move_insn (operands[0], out);
16460
16461   DONE;
16462 })
16463
16464 ;; Produce a tri-state integer (-1, 0, 1) from condition codes.
16465
16466 (define_expand "cmpintqi"
16467   [(set (match_dup 1)
16468         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16469    (set (match_dup 2)
16470         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16471    (parallel [(set (match_operand:QI 0 "register_operand")
16472                    (minus:QI (match_dup 1)
16473                              (match_dup 2)))
16474               (clobber (reg:CC FLAGS_REG))])]
16475   ""
16476 {
16477   operands[1] = gen_reg_rtx (QImode);
16478   operands[2] = gen_reg_rtx (QImode);
16479 })
16480
16481 ;; memcmp recognizers.  The `cmpsb' opcode does nothing if the count is
16482 ;; zero.  Emit extra code to make sure that a zero-length compare is EQ.
16483
16484 (define_expand "cmpstrnqi_nz_1"
16485   [(parallel [(set (reg:CC FLAGS_REG)
16486                    (compare:CC (match_operand 4 "memory_operand")
16487                                (match_operand 5 "memory_operand")))
16488               (use (match_operand 2 "register_operand"))
16489               (use (match_operand:SI 3 "immediate_operand"))
16490               (clobber (match_operand 0 "register_operand"))
16491               (clobber (match_operand 1 "register_operand"))
16492               (clobber (match_dup 2))])]
16493   ""
16494   "ix86_current_function_needs_cld = 1;")
16495
16496 (define_insn "*cmpstrnqi_nz_1"
16497   [(set (reg:CC FLAGS_REG)
16498         (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
16499                     (mem:BLK (match_operand:P 5 "register_operand" "1"))))
16500    (use (match_operand:P 6 "register_operand" "2"))
16501    (use (match_operand:SI 3 "immediate_operand" "i"))
16502    (clobber (match_operand:P 0 "register_operand" "=S"))
16503    (clobber (match_operand:P 1 "register_operand" "=D"))
16504    (clobber (match_operand:P 2 "register_operand" "=c"))]
16505   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16506   "%^repz{%;} cmpsb"
16507   [(set_attr "type" "str")
16508    (set_attr "mode" "QI")
16509    (set (attr "prefix_rex")
16510         (if_then_else
16511           (match_test "<P:MODE>mode == DImode")
16512           (const_string "0")
16513           (const_string "*")))
16514    (set_attr "prefix_rep" "1")])
16515
16516 ;; The same, but the count is not known to not be zero.
16517
16518 (define_expand "cmpstrnqi_1"
16519   [(parallel [(set (reg:CC FLAGS_REG)
16520                 (if_then_else:CC (ne (match_operand 2 "register_operand")
16521                                      (const_int 0))
16522                   (compare:CC (match_operand 4 "memory_operand")
16523                               (match_operand 5 "memory_operand"))
16524                   (const_int 0)))
16525               (use (match_operand:SI 3 "immediate_operand"))
16526               (use (reg:CC FLAGS_REG))
16527               (clobber (match_operand 0 "register_operand"))
16528               (clobber (match_operand 1 "register_operand"))
16529               (clobber (match_dup 2))])]
16530   ""
16531   "ix86_current_function_needs_cld = 1;")
16532
16533 (define_insn "*cmpstrnqi_1"
16534   [(set (reg:CC FLAGS_REG)
16535         (if_then_else:CC (ne (match_operand:P 6 "register_operand" "2")
16536                              (const_int 0))
16537           (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
16538                       (mem:BLK (match_operand:P 5 "register_operand" "1")))
16539           (const_int 0)))
16540    (use (match_operand:SI 3 "immediate_operand" "i"))
16541    (use (reg:CC FLAGS_REG))
16542    (clobber (match_operand:P 0 "register_operand" "=S"))
16543    (clobber (match_operand:P 1 "register_operand" "=D"))
16544    (clobber (match_operand:P 2 "register_operand" "=c"))]
16545   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16546   "%^repz{%;} cmpsb"
16547   [(set_attr "type" "str")
16548    (set_attr "mode" "QI")
16549    (set (attr "prefix_rex")
16550         (if_then_else
16551           (match_test "<P:MODE>mode == DImode")
16552           (const_string "0")
16553           (const_string "*")))
16554    (set_attr "prefix_rep" "1")])
16555
16556 (define_expand "strlen<mode>"
16557   [(set (match_operand:P 0 "register_operand")
16558         (unspec:P [(match_operand:BLK 1 "general_operand")
16559                    (match_operand:QI 2 "immediate_operand")
16560                    (match_operand 3 "immediate_operand")]
16561                   UNSPEC_SCAS))]
16562   ""
16563 {
16564  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
16565    DONE;
16566  else
16567    FAIL;
16568 })
16569
16570 (define_expand "strlenqi_1"
16571   [(parallel [(set (match_operand 0 "register_operand")
16572                    (match_operand 2))
16573               (clobber (match_operand 1 "register_operand"))
16574               (clobber (reg:CC FLAGS_REG))])]
16575   ""
16576   "ix86_current_function_needs_cld = 1;")
16577
16578 (define_insn "*strlenqi_1"
16579   [(set (match_operand:P 0 "register_operand" "=&c")
16580         (unspec:P [(mem:BLK (match_operand:P 5 "register_operand" "1"))
16581                    (match_operand:QI 2 "register_operand" "a")
16582                    (match_operand:P 3 "immediate_operand" "i")
16583                    (match_operand:P 4 "register_operand" "0")] UNSPEC_SCAS))
16584    (clobber (match_operand:P 1 "register_operand" "=D"))
16585    (clobber (reg:CC FLAGS_REG))]
16586   "!(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16587   "%^repnz{%;} scasb"
16588   [(set_attr "type" "str")
16589    (set_attr "mode" "QI")
16590    (set (attr "prefix_rex")
16591         (if_then_else
16592           (match_test "<P:MODE>mode == DImode")
16593           (const_string "0")
16594           (const_string "*")))
16595    (set_attr "prefix_rep" "1")])
16596
16597 ;; Peephole optimizations to clean up after cmpstrn*.  This should be
16598 ;; handled in combine, but it is not currently up to the task.
16599 ;; When used for their truth value, the cmpstrn* expanders generate
16600 ;; code like this:
16601 ;;
16602 ;;   repz cmpsb
16603 ;;   seta       %al
16604 ;;   setb       %dl
16605 ;;   cmpb       %al, %dl
16606 ;;   jcc        label
16607 ;;
16608 ;; The intermediate three instructions are unnecessary.
16609
16610 ;; This one handles cmpstrn*_nz_1...
16611 (define_peephole2
16612   [(parallel[
16613      (set (reg:CC FLAGS_REG)
16614           (compare:CC (mem:BLK (match_operand 4 "register_operand"))
16615                       (mem:BLK (match_operand 5 "register_operand"))))
16616      (use (match_operand 6 "register_operand"))
16617      (use (match_operand:SI 3 "immediate_operand"))
16618      (clobber (match_operand 0 "register_operand"))
16619      (clobber (match_operand 1 "register_operand"))
16620      (clobber (match_operand 2 "register_operand"))])
16621    (set (match_operand:QI 7 "register_operand")
16622         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16623    (set (match_operand:QI 8 "register_operand")
16624         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16625    (set (reg FLAGS_REG)
16626         (compare (match_dup 7) (match_dup 8)))
16627   ]
16628   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16629   [(parallel[
16630      (set (reg:CC FLAGS_REG)
16631           (compare:CC (mem:BLK (match_dup 4))
16632                       (mem:BLK (match_dup 5))))
16633      (use (match_dup 6))
16634      (use (match_dup 3))
16635      (clobber (match_dup 0))
16636      (clobber (match_dup 1))
16637      (clobber (match_dup 2))])])
16638
16639 ;; ...and this one handles cmpstrn*_1.
16640 (define_peephole2
16641   [(parallel[
16642      (set (reg:CC FLAGS_REG)
16643           (if_then_else:CC (ne (match_operand 6 "register_operand")
16644                                (const_int 0))
16645             (compare:CC (mem:BLK (match_operand 4 "register_operand"))
16646                         (mem:BLK (match_operand 5 "register_operand")))
16647             (const_int 0)))
16648      (use (match_operand:SI 3 "immediate_operand"))
16649      (use (reg:CC FLAGS_REG))
16650      (clobber (match_operand 0 "register_operand"))
16651      (clobber (match_operand 1 "register_operand"))
16652      (clobber (match_operand 2 "register_operand"))])
16653    (set (match_operand:QI 7 "register_operand")
16654         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16655    (set (match_operand:QI 8 "register_operand")
16656         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16657    (set (reg FLAGS_REG)
16658         (compare (match_dup 7) (match_dup 8)))
16659   ]
16660   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16661   [(parallel[
16662      (set (reg:CC FLAGS_REG)
16663           (if_then_else:CC (ne (match_dup 6)
16664                                (const_int 0))
16665             (compare:CC (mem:BLK (match_dup 4))
16666                         (mem:BLK (match_dup 5)))
16667             (const_int 0)))
16668      (use (match_dup 3))
16669      (use (reg:CC FLAGS_REG))
16670      (clobber (match_dup 0))
16671      (clobber (match_dup 1))
16672      (clobber (match_dup 2))])])
16673 \f
16674 ;; Conditional move instructions.
16675
16676 (define_expand "mov<mode>cc"
16677   [(set (match_operand:SWIM 0 "register_operand")
16678         (if_then_else:SWIM (match_operand 1 "comparison_operator")
16679                            (match_operand:SWIM 2 "<general_operand>")
16680                            (match_operand:SWIM 3 "<general_operand>")))]
16681   ""
16682   "if (ix86_expand_int_movcc (operands)) DONE; else FAIL;")
16683
16684 ;; Data flow gets confused by our desire for `sbbl reg,reg', and clearing
16685 ;; the register first winds up with `sbbl $0,reg', which is also weird.
16686 ;; So just document what we're doing explicitly.
16687
16688 (define_expand "x86_mov<mode>cc_0_m1"
16689   [(parallel
16690     [(set (match_operand:SWI48 0 "register_operand")
16691           (if_then_else:SWI48
16692             (match_operator:SWI48 2 "ix86_carry_flag_operator"
16693              [(match_operand 1 "flags_reg_operand")
16694               (const_int 0)])
16695             (const_int -1)
16696             (const_int 0)))
16697      (clobber (reg:CC FLAGS_REG))])])
16698
16699 (define_insn "*x86_mov<mode>cc_0_m1"
16700   [(set (match_operand:SWI48 0 "register_operand" "=r")
16701         (if_then_else:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16702                              [(reg FLAGS_REG) (const_int 0)])
16703           (const_int -1)
16704           (const_int 0)))
16705    (clobber (reg:CC FLAGS_REG))]
16706   ""
16707   "sbb{<imodesuffix>}\t%0, %0"
16708   ; Since we don't have the proper number of operands for an alu insn,
16709   ; fill in all the blanks.
16710   [(set_attr "type" "alu")
16711    (set_attr "use_carry" "1")
16712    (set_attr "pent_pair" "pu")
16713    (set_attr "memory" "none")
16714    (set_attr "imm_disp" "false")
16715    (set_attr "mode" "<MODE>")
16716    (set_attr "length_immediate" "0")])
16717
16718 (define_insn "*x86_mov<mode>cc_0_m1_se"
16719   [(set (match_operand:SWI48 0 "register_operand" "=r")
16720         (sign_extract:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16721                              [(reg FLAGS_REG) (const_int 0)])
16722                             (const_int 1)
16723                             (const_int 0)))
16724    (clobber (reg:CC FLAGS_REG))]
16725   ""
16726   "sbb{<imodesuffix>}\t%0, %0"
16727   [(set_attr "type" "alu")
16728    (set_attr "use_carry" "1")
16729    (set_attr "pent_pair" "pu")
16730    (set_attr "memory" "none")
16731    (set_attr "imm_disp" "false")
16732    (set_attr "mode" "<MODE>")
16733    (set_attr "length_immediate" "0")])
16734
16735 (define_insn "*x86_mov<mode>cc_0_m1_neg"
16736   [(set (match_operand:SWI48 0 "register_operand" "=r")
16737         (neg:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16738                     [(reg FLAGS_REG) (const_int 0)])))
16739    (clobber (reg:CC FLAGS_REG))]
16740   ""
16741   "sbb{<imodesuffix>}\t%0, %0"
16742   [(set_attr "type" "alu")
16743    (set_attr "use_carry" "1")
16744    (set_attr "pent_pair" "pu")
16745    (set_attr "memory" "none")
16746    (set_attr "imm_disp" "false")
16747    (set_attr "mode" "<MODE>")
16748    (set_attr "length_immediate" "0")])
16749
16750 (define_insn "*mov<mode>cc_noc"
16751   [(set (match_operand:SWI248 0 "register_operand" "=r,r")
16752         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16753                                [(reg FLAGS_REG) (const_int 0)])
16754           (match_operand:SWI248 2 "nonimmediate_operand" "rm,0")
16755           (match_operand:SWI248 3 "nonimmediate_operand" "0,rm")))]
16756   "TARGET_CMOVE && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16757   "@
16758    cmov%O2%C1\t{%2, %0|%0, %2}
16759    cmov%O2%c1\t{%3, %0|%0, %3}"
16760   [(set_attr "type" "icmov")
16761    (set_attr "mode" "<MODE>")])
16762
16763 ;; Don't do conditional moves with memory inputs.  This splitter helps
16764 ;; register starved x86_32 by forcing inputs into registers before reload.
16765 (define_split
16766   [(set (match_operand:SWI248 0 "register_operand")
16767         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16768                                [(reg FLAGS_REG) (const_int 0)])
16769           (match_operand:SWI248 2 "nonimmediate_operand")
16770           (match_operand:SWI248 3 "nonimmediate_operand")))]
16771   "!TARGET_64BIT && TARGET_CMOVE
16772    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16773    && (MEM_P (operands[2]) || MEM_P (operands[3]))
16774    && can_create_pseudo_p ()
16775    && optimize_insn_for_speed_p ()"
16776   [(set (match_dup 0)
16777         (if_then_else:SWI248 (match_dup 1) (match_dup 2) (match_dup 3)))]
16778 {
16779   if (MEM_P (operands[2]))
16780     operands[2] = force_reg (<MODE>mode, operands[2]);
16781   if (MEM_P (operands[3]))
16782     operands[3] = force_reg (<MODE>mode, operands[3]);
16783 })
16784
16785 (define_insn "*movqicc_noc"
16786   [(set (match_operand:QI 0 "register_operand" "=r,r")
16787         (if_then_else:QI (match_operator 1 "ix86_comparison_operator"
16788                            [(reg FLAGS_REG) (const_int 0)])
16789                       (match_operand:QI 2 "register_operand" "r,0")
16790                       (match_operand:QI 3 "register_operand" "0,r")))]
16791   "TARGET_CMOVE && !TARGET_PARTIAL_REG_STALL"
16792   "#"
16793   [(set_attr "type" "icmov")
16794    (set_attr "mode" "QI")])
16795
16796 (define_split
16797   [(set (match_operand:SWI12 0 "register_operand")
16798         (if_then_else:SWI12 (match_operator 1 "ix86_comparison_operator"
16799                               [(reg FLAGS_REG) (const_int 0)])
16800                       (match_operand:SWI12 2 "register_operand")
16801                       (match_operand:SWI12 3 "register_operand")))]
16802   "TARGET_CMOVE && !TARGET_PARTIAL_REG_STALL
16803    && reload_completed"
16804   [(set (match_dup 0)
16805         (if_then_else:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
16806 {
16807   operands[0] = gen_lowpart (SImode, operands[0]);
16808   operands[2] = gen_lowpart (SImode, operands[2]);
16809   operands[3] = gen_lowpart (SImode, operands[3]);
16810 })
16811
16812 ;; Don't do conditional moves with memory inputs
16813 (define_peephole2
16814   [(match_scratch:SWI248 2 "r")
16815    (set (match_operand:SWI248 0 "register_operand")
16816         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16817                                [(reg FLAGS_REG) (const_int 0)])
16818           (match_dup 0)
16819           (match_operand:SWI248 3 "memory_operand")))]
16820   "TARGET_CMOVE && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16821    && optimize_insn_for_speed_p ()"
16822   [(set (match_dup 2) (match_dup 3))
16823    (set (match_dup 0)
16824         (if_then_else:SWI248 (match_dup 1) (match_dup 0) (match_dup 2)))])
16825
16826 (define_peephole2
16827   [(match_scratch:SWI248 2 "r")
16828    (set (match_operand:SWI248 0 "register_operand")
16829         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16830                                [(reg FLAGS_REG) (const_int 0)])
16831           (match_operand:SWI248 3 "memory_operand")
16832           (match_dup 0)))]
16833   "TARGET_CMOVE && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16834    && optimize_insn_for_speed_p ()"
16835   [(set (match_dup 2) (match_dup 3))
16836    (set (match_dup 0)
16837         (if_then_else:SWI248 (match_dup 1) (match_dup 2) (match_dup 0)))])
16838
16839 (define_expand "mov<mode>cc"
16840   [(set (match_operand:X87MODEF 0 "register_operand")
16841         (if_then_else:X87MODEF
16842           (match_operand 1 "comparison_operator")
16843           (match_operand:X87MODEF 2 "register_operand")
16844           (match_operand:X87MODEF 3 "register_operand")))]
16845   "(TARGET_80387 && TARGET_CMOVE)
16846    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
16847   "if (ix86_expand_fp_movcc (operands)) DONE; else FAIL;")
16848
16849 (define_insn "*movxfcc_1"
16850   [(set (match_operand:XF 0 "register_operand" "=f,f")
16851         (if_then_else:XF (match_operator 1 "fcmov_comparison_operator"
16852                                 [(reg FLAGS_REG) (const_int 0)])
16853                       (match_operand:XF 2 "register_operand" "f,0")
16854                       (match_operand:XF 3 "register_operand" "0,f")))]
16855   "TARGET_80387 && TARGET_CMOVE"
16856   "@
16857    fcmov%F1\t{%2, %0|%0, %2}
16858    fcmov%f1\t{%3, %0|%0, %3}"
16859   [(set_attr "type" "fcmov")
16860    (set_attr "mode" "XF")])
16861
16862 (define_insn "*movdfcc_1"
16863   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r,r ,r")
16864         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
16865                                 [(reg FLAGS_REG) (const_int 0)])
16866                       (match_operand:DF 2 "nonimmediate_operand"
16867                                                "f ,0,rm,0 ,rm,0")
16868                       (match_operand:DF 3 "nonimmediate_operand"
16869                                                "0 ,f,0 ,rm,0, rm")))]
16870   "TARGET_80387 && TARGET_CMOVE
16871    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16872   "@
16873    fcmov%F1\t{%2, %0|%0, %2}
16874    fcmov%f1\t{%3, %0|%0, %3}
16875    #
16876    #
16877    cmov%O2%C1\t{%2, %0|%0, %2}
16878    cmov%O2%c1\t{%3, %0|%0, %3}"
16879   [(set_attr "isa" "*,*,nox64,nox64,x64,x64")
16880    (set_attr "type" "fcmov,fcmov,multi,multi,icmov,icmov")
16881    (set_attr "mode" "DF,DF,DI,DI,DI,DI")])
16882
16883 (define_split
16884   [(set (match_operand:DF 0 "register_and_not_any_fp_reg_operand")
16885         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
16886                                 [(reg FLAGS_REG) (const_int 0)])
16887                       (match_operand:DF 2 "nonimmediate_operand")
16888                       (match_operand:DF 3 "nonimmediate_operand")))]
16889   "!TARGET_64BIT && reload_completed"
16890   [(set (match_dup 2)
16891         (if_then_else:SI (match_dup 1) (match_dup 4) (match_dup 5)))
16892    (set (match_dup 3)
16893         (if_then_else:SI (match_dup 1) (match_dup 6) (match_dup 7)))]
16894 {
16895   split_double_mode (DImode, &operands[2], 2, &operands[4], &operands[6]);
16896   split_double_mode (DImode, &operands[0], 1, &operands[2], &operands[3]);
16897 })
16898
16899 (define_insn "*movsfcc_1_387"
16900   [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
16901         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
16902                                 [(reg FLAGS_REG) (const_int 0)])
16903                       (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
16904                       (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
16905   "TARGET_80387 && TARGET_CMOVE
16906    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16907   "@
16908    fcmov%F1\t{%2, %0|%0, %2}
16909    fcmov%f1\t{%3, %0|%0, %3}
16910    cmov%O2%C1\t{%2, %0|%0, %2}
16911    cmov%O2%c1\t{%3, %0|%0, %3}"
16912   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
16913    (set_attr "mode" "SF,SF,SI,SI")])
16914
16915 ;; Don't do conditional moves with memory inputs.  This splitter helps
16916 ;; register starved x86_32 by forcing inputs into registers before reload.
16917 (define_split
16918   [(set (match_operand:MODEF 0 "register_operand")
16919         (if_then_else:MODEF (match_operator 1 "ix86_comparison_operator"
16920                               [(reg FLAGS_REG) (const_int 0)])
16921           (match_operand:MODEF 2 "nonimmediate_operand")
16922           (match_operand:MODEF 3 "nonimmediate_operand")))]
16923   "!TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
16924    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16925    && (MEM_P (operands[2]) || MEM_P (operands[3]))
16926    && can_create_pseudo_p ()
16927    && optimize_insn_for_speed_p ()"
16928   [(set (match_dup 0)
16929         (if_then_else:MODEF (match_dup 1) (match_dup 2) (match_dup 3)))]
16930 {
16931   if (MEM_P (operands[2]))
16932     operands[2] = force_reg (<MODE>mode, operands[2]);
16933   if (MEM_P (operands[3]))
16934     operands[3] = force_reg (<MODE>mode, operands[3]);
16935 })
16936
16937 ;; Don't do conditional moves with memory inputs
16938 (define_peephole2
16939   [(match_scratch:MODEF 2 "r")
16940    (set (match_operand:MODEF 0 "register_and_not_any_fp_reg_operand")
16941         (if_then_else:MODEF (match_operator 1 "fcmov_comparison_operator"
16942                               [(reg FLAGS_REG) (const_int 0)])
16943           (match_dup 0)
16944           (match_operand:MODEF 3 "memory_operand")))]
16945   "(<MODE>mode != DFmode || TARGET_64BIT)
16946    && TARGET_80387 && TARGET_CMOVE
16947    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16948    && optimize_insn_for_speed_p ()"
16949   [(set (match_dup 2) (match_dup 3))
16950    (set (match_dup 0)
16951         (if_then_else:MODEF (match_dup 1) (match_dup 0) (match_dup 2)))])
16952
16953 (define_peephole2
16954   [(match_scratch:MODEF 2 "r")
16955    (set (match_operand:MODEF 0 "register_and_not_any_fp_reg_operand")
16956         (if_then_else:MODEF (match_operator 1 "fcmov_comparison_operator"
16957                               [(reg FLAGS_REG) (const_int 0)])
16958           (match_operand:MODEF 3 "memory_operand")
16959           (match_dup 0)))]
16960   "(<MODE>mode != DFmode || TARGET_64BIT)
16961    && TARGET_80387 && TARGET_CMOVE
16962    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16963    && optimize_insn_for_speed_p ()"
16964   [(set (match_dup 2) (match_dup 3))
16965    (set (match_dup 0)
16966         (if_then_else:MODEF (match_dup 1) (match_dup 2) (match_dup 0)))])
16967
16968 ;; All moves in XOP pcmov instructions are 128 bits and hence we restrict
16969 ;; the scalar versions to have only XMM registers as operands.
16970
16971 ;; XOP conditional move
16972 (define_insn "*xop_pcmov_<mode>"
16973   [(set (match_operand:MODEF 0 "register_operand" "=x")
16974         (if_then_else:MODEF
16975           (match_operand:MODEF 1 "register_operand" "x")
16976           (match_operand:MODEF 2 "register_operand" "x")
16977           (match_operand:MODEF 3 "register_operand" "x")))]
16978   "TARGET_XOP"
16979   "vpcmov\t{%1, %3, %2, %0|%0, %2, %3, %1}"
16980   [(set_attr "type" "sse4arg")])
16981
16982 ;; These versions of the min/max patterns are intentionally ignorant of
16983 ;; their behavior wrt -0.0 and NaN (via the commutative operand mark).
16984 ;; Since both the tree-level MAX_EXPR and the rtl-level SMAX operator
16985 ;; are undefined in this condition, we're certain this is correct.
16986
16987 (define_insn "<code><mode>3"
16988   [(set (match_operand:MODEF 0 "register_operand" "=x,v")
16989         (smaxmin:MODEF
16990           (match_operand:MODEF 1 "nonimmediate_operand" "%0,v")
16991           (match_operand:MODEF 2 "nonimmediate_operand" "xm,vm")))]
16992   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
16993   "@
16994    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
16995    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16996   [(set_attr "isa" "noavx,avx")
16997    (set_attr "prefix" "orig,vex")
16998    (set_attr "type" "sseadd")
16999    (set_attr "mode" "<MODE>")])
17000
17001 ;; These versions of the min/max patterns implement exactly the operations
17002 ;;   min = (op1 < op2 ? op1 : op2)
17003 ;;   max = (!(op1 < op2) ? op1 : op2)
17004 ;; Their operands are not commutative, and thus they may be used in the
17005 ;; presence of -0.0 and NaN.
17006
17007 (define_int_iterator IEEE_MAXMIN
17008         [UNSPEC_IEEE_MAX
17009          UNSPEC_IEEE_MIN])
17010
17011 (define_int_attr ieee_maxmin
17012         [(UNSPEC_IEEE_MAX "max")
17013          (UNSPEC_IEEE_MIN "min")])
17014
17015 (define_insn "*ieee_s<ieee_maxmin><mode>3"
17016   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
17017         (unspec:MODEF
17018           [(match_operand:MODEF 1 "register_operand" "0,x")
17019            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]
17020           IEEE_MAXMIN))]
17021   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
17022   "@
17023    <ieee_maxmin><ssemodesuffix>\t{%2, %0|%0, %2}
17024    v<ieee_maxmin><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
17025   [(set_attr "isa" "noavx,avx")
17026    (set_attr "prefix" "orig,vex")
17027    (set_attr "type" "sseadd")
17028    (set_attr "mode" "<MODE>")])
17029
17030 ;; Make two stack loads independent:
17031 ;;   fld aa              fld aa
17032 ;;   fld %st(0)     ->   fld bb
17033 ;;   fmul bb             fmul %st(1), %st
17034 ;;
17035 ;; Actually we only match the last two instructions for simplicity.
17036 (define_peephole2
17037   [(set (match_operand 0 "fp_register_operand")
17038         (match_operand 1 "fp_register_operand"))
17039    (set (match_dup 0)
17040         (match_operator 2 "binary_fp_operator"
17041            [(match_dup 0)
17042             (match_operand 3 "memory_operand")]))]
17043   "REGNO (operands[0]) != REGNO (operands[1])"
17044   [(set (match_dup 0) (match_dup 3))
17045    (set (match_dup 0) (match_dup 4))]
17046
17047   ;; The % modifier is not operational anymore in peephole2's, so we have to
17048   ;; swap the operands manually in the case of addition and multiplication.
17049 {
17050   rtx op0, op1;
17051
17052   if (COMMUTATIVE_ARITH_P (operands[2]))
17053     op0 = operands[0], op1 = operands[1];
17054   else
17055     op0 = operands[1], op1 = operands[0];
17056
17057   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]),
17058                                 GET_MODE (operands[2]),
17059                                 op0, op1);
17060 })
17061
17062 ;; Conditional addition patterns
17063 (define_expand "add<mode>cc"
17064   [(match_operand:SWI 0 "register_operand")
17065    (match_operand 1 "ordered_comparison_operator")
17066    (match_operand:SWI 2 "register_operand")
17067    (match_operand:SWI 3 "const_int_operand")]
17068   ""
17069   "if (ix86_expand_int_addcc (operands)) DONE; else FAIL;")
17070 \f
17071 ;; Misc patterns (?)
17072
17073 ;; This pattern exists to put a dependency on all ebp-based memory accesses.
17074 ;; Otherwise there will be nothing to keep
17075 ;;
17076 ;; [(set (reg ebp) (reg esp))]
17077 ;; [(set (reg esp) (plus (reg esp) (const_int -160000)))
17078 ;;  (clobber (eflags)]
17079 ;; [(set (mem (plus (reg ebp) (const_int -160000))) (const_int 0))]
17080 ;;
17081 ;; in proper program order.
17082
17083 (define_insn "pro_epilogue_adjust_stack_<mode>_add"
17084   [(set (match_operand:P 0 "register_operand" "=r,r")
17085         (plus:P (match_operand:P 1 "register_operand" "0,r")
17086                 (match_operand:P 2 "<nonmemory_operand>" "r<i>,l<i>")))
17087    (clobber (reg:CC FLAGS_REG))
17088    (clobber (mem:BLK (scratch)))]
17089   ""
17090 {
17091   switch (get_attr_type (insn))
17092     {
17093     case TYPE_IMOV:
17094       return "mov{<imodesuffix>}\t{%1, %0|%0, %1}";
17095
17096     case TYPE_ALU:
17097       gcc_assert (rtx_equal_p (operands[0], operands[1]));
17098       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
17099         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
17100
17101       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
17102
17103     default:
17104       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
17105       return "lea{<imodesuffix>}\t{%E2, %0|%0, %E2}";
17106     }
17107 }
17108   [(set (attr "type")
17109         (cond [(and (eq_attr "alternative" "0")
17110                     (not (match_test "TARGET_OPT_AGU")))
17111                  (const_string "alu")
17112                (match_operand:<MODE> 2 "const0_operand")
17113                  (const_string "imov")
17114               ]
17115               (const_string "lea")))
17116    (set (attr "length_immediate")
17117         (cond [(eq_attr "type" "imov")
17118                  (const_string "0")
17119                (and (eq_attr "type" "alu")
17120                     (match_operand 2 "const128_operand"))
17121                  (const_string "1")
17122               ]
17123               (const_string "*")))
17124    (set_attr "mode" "<MODE>")])
17125
17126 (define_insn "pro_epilogue_adjust_stack_<mode>_sub"
17127   [(set (match_operand:P 0 "register_operand" "=r")
17128         (minus:P (match_operand:P 1 "register_operand" "0")
17129                  (match_operand:P 2 "register_operand" "r")))
17130    (clobber (reg:CC FLAGS_REG))
17131    (clobber (mem:BLK (scratch)))]
17132   ""
17133   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
17134   [(set_attr "type" "alu")
17135    (set_attr "mode" "<MODE>")])
17136
17137 (define_insn "allocate_stack_worker_probe_<mode>"
17138   [(set (match_operand:P 0 "register_operand" "=a")
17139         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")]
17140                             UNSPECV_STACK_PROBE))
17141    (clobber (reg:CC FLAGS_REG))]
17142   "ix86_target_stack_probe ()"
17143   "call\t___chkstk_ms"
17144   [(set_attr "type" "multi")
17145    (set_attr "length" "5")])
17146
17147 (define_expand "allocate_stack"
17148   [(match_operand 0 "register_operand")
17149    (match_operand 1 "general_operand")]
17150   "ix86_target_stack_probe ()"
17151 {
17152   rtx x;
17153
17154 #ifndef CHECK_STACK_LIMIT
17155 #define CHECK_STACK_LIMIT 0
17156 #endif
17157
17158   if (CHECK_STACK_LIMIT && CONST_INT_P (operands[1])
17159       && INTVAL (operands[1]) < CHECK_STACK_LIMIT)
17160     x = operands[1];
17161   else
17162     {
17163       rtx (*insn) (rtx, rtx);
17164
17165       x = copy_to_mode_reg (Pmode, operands[1]);
17166
17167       insn = (TARGET_64BIT
17168               ? gen_allocate_stack_worker_probe_di
17169               : gen_allocate_stack_worker_probe_si);
17170
17171       emit_insn (insn (x, x));
17172     }
17173
17174   x = expand_simple_binop (Pmode, MINUS, stack_pointer_rtx, x,
17175                            stack_pointer_rtx, 0, OPTAB_DIRECT);
17176
17177   if (x != stack_pointer_rtx)
17178     emit_move_insn (stack_pointer_rtx, x);
17179
17180   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
17181   DONE;
17182 })
17183
17184 ;; Use IOR for stack probes, this is shorter.
17185 (define_expand "probe_stack"
17186   [(match_operand 0 "memory_operand")]
17187   ""
17188 {
17189   rtx (*gen_ior3) (rtx, rtx, rtx);
17190
17191   gen_ior3 = (GET_MODE (operands[0]) == DImode
17192               ? gen_iordi3 : gen_iorsi3);
17193
17194   emit_insn (gen_ior3 (operands[0], operands[0], const0_rtx));
17195   DONE;
17196 })
17197
17198 (define_insn "adjust_stack_and_probe<mode>"
17199   [(set (match_operand:P 0 "register_operand" "=r")
17200         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")]
17201                             UNSPECV_PROBE_STACK_RANGE))
17202    (set (reg:P SP_REG)
17203         (minus:P (reg:P SP_REG) (match_operand:P 2 "const_int_operand" "n")))
17204    (clobber (reg:CC FLAGS_REG))
17205    (clobber (mem:BLK (scratch)))]
17206   ""
17207   "* return output_adjust_stack_and_probe (operands[0]);"
17208   [(set_attr "type" "multi")])
17209
17210 (define_insn "probe_stack_range<mode>"
17211   [(set (match_operand:P 0 "register_operand" "=r")
17212         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
17213                             (match_operand:P 2 "const_int_operand" "n")]
17214                             UNSPECV_PROBE_STACK_RANGE))
17215    (clobber (reg:CC FLAGS_REG))]
17216   ""
17217   "* return output_probe_stack_range (operands[0], operands[2]);"
17218   [(set_attr "type" "multi")])
17219
17220 (define_expand "builtin_setjmp_receiver"
17221   [(label_ref (match_operand 0))]
17222   "!TARGET_64BIT && flag_pic"
17223 {
17224 #if TARGET_MACHO
17225   if (TARGET_MACHO)
17226     {
17227       rtx xops[3];
17228       rtx_code_label *label_rtx = gen_label_rtx ();
17229       emit_insn (gen_set_got_labelled (pic_offset_table_rtx, label_rtx));
17230       xops[0] = xops[1] = pic_offset_table_rtx;
17231       xops[2] = machopic_gen_offset (gen_rtx_LABEL_REF (SImode, label_rtx));
17232       ix86_expand_binary_operator (MINUS, SImode, xops);
17233     }
17234   else
17235 #endif
17236     emit_insn (gen_set_got (pic_offset_table_rtx));
17237   DONE;
17238 })
17239
17240 ;; Avoid redundant prefixes by splitting HImode arithmetic to SImode.
17241 ;; Do not split instructions with mask registers.
17242 (define_split
17243   [(set (match_operand 0 "general_reg_operand")
17244         (match_operator 3 "promotable_binary_operator"
17245            [(match_operand 1 "general_reg_operand")
17246             (match_operand 2 "aligned_operand")]))
17247    (clobber (reg:CC FLAGS_REG))]
17248   "! TARGET_PARTIAL_REG_STALL && reload_completed
17249    && ((GET_MODE (operands[0]) == HImode
17250         && ((optimize_function_for_speed_p (cfun) && !TARGET_FAST_PREFIX)
17251             /* ??? next two lines just !satisfies_constraint_K (...) */
17252             || !CONST_INT_P (operands[2])
17253             || satisfies_constraint_K (operands[2])))
17254        || (GET_MODE (operands[0]) == QImode
17255            && (TARGET_PROMOTE_QImode || optimize_function_for_size_p (cfun))))"
17256   [(parallel [(set (match_dup 0)
17257                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
17258               (clobber (reg:CC FLAGS_REG))])]
17259 {
17260   operands[0] = gen_lowpart (SImode, operands[0]);
17261   operands[1] = gen_lowpart (SImode, operands[1]);
17262   if (GET_CODE (operands[3]) != ASHIFT)
17263     operands[2] = gen_lowpart (SImode, operands[2]);
17264   operands[3] = shallow_copy_rtx (operands[3]);
17265   PUT_MODE (operands[3], SImode);
17266 })
17267
17268 ; Promote the QImode tests, as i386 has encoding of the AND
17269 ; instruction with 32-bit sign-extended immediate and thus the
17270 ; instruction size is unchanged, except in the %eax case for
17271 ; which it is increased by one byte, hence the ! optimize_size.
17272 (define_split
17273   [(set (match_operand 0 "flags_reg_operand")
17274         (match_operator 2 "compare_operator"
17275           [(and (match_operand 3 "aligned_operand")
17276                 (match_operand 4 "const_int_operand"))
17277            (const_int 0)]))
17278    (set (match_operand 1 "register_operand")
17279         (and (match_dup 3) (match_dup 4)))]
17280   "! TARGET_PARTIAL_REG_STALL && reload_completed
17281    && optimize_insn_for_speed_p ()
17282    && ((GET_MODE (operands[1]) == HImode && ! TARGET_FAST_PREFIX)
17283        || (GET_MODE (operands[1]) == QImode && TARGET_PROMOTE_QImode))
17284    /* Ensure that the operand will remain sign-extended immediate.  */
17285    && ix86_match_ccmode (insn, INTVAL (operands[4]) >= 0 ? CCNOmode : CCZmode)"
17286   [(parallel [(set (match_dup 0)
17287                    (match_op_dup 2 [(and:SI (match_dup 3) (match_dup 4))
17288                                     (const_int 0)]))
17289               (set (match_dup 1)
17290                    (and:SI (match_dup 3) (match_dup 4)))])]
17291 {
17292   operands[4]
17293     = gen_int_mode (INTVAL (operands[4])
17294                     & GET_MODE_MASK (GET_MODE (operands[1])), SImode);
17295   operands[1] = gen_lowpart (SImode, operands[1]);
17296   operands[3] = gen_lowpart (SImode, operands[3]);
17297 })
17298
17299 ; Don't promote the QImode tests, as i386 doesn't have encoding of
17300 ; the TEST instruction with 32-bit sign-extended immediate and thus
17301 ; the instruction size would at least double, which is not what we
17302 ; want even with ! optimize_size.
17303 (define_split
17304   [(set (match_operand 0 "flags_reg_operand")
17305         (match_operator 1 "compare_operator"
17306           [(and (match_operand:HI 2 "aligned_operand")
17307                 (match_operand:HI 3 "const_int_operand"))
17308            (const_int 0)]))]
17309   "! TARGET_PARTIAL_REG_STALL && reload_completed
17310    && ! TARGET_FAST_PREFIX
17311    && optimize_insn_for_speed_p ()
17312    /* Ensure that the operand will remain sign-extended immediate.  */
17313    && ix86_match_ccmode (insn, INTVAL (operands[3]) >= 0 ? CCNOmode : CCZmode)"
17314   [(set (match_dup 0)
17315         (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
17316                          (const_int 0)]))]
17317 {
17318   operands[3]
17319     = gen_int_mode (INTVAL (operands[3])
17320                     & GET_MODE_MASK (GET_MODE (operands[2])), SImode);
17321   operands[2] = gen_lowpart (SImode, operands[2]);
17322 })
17323
17324 (define_split
17325   [(set (match_operand 0 "register_operand")
17326         (neg (match_operand 1 "register_operand")))
17327    (clobber (reg:CC FLAGS_REG))]
17328   "! TARGET_PARTIAL_REG_STALL && reload_completed
17329    && (GET_MODE (operands[0]) == HImode
17330        || (GET_MODE (operands[0]) == QImode
17331            && (TARGET_PROMOTE_QImode
17332                || optimize_insn_for_size_p ())))"
17333   [(parallel [(set (match_dup 0)
17334                    (neg:SI (match_dup 1)))
17335               (clobber (reg:CC FLAGS_REG))])]
17336 {
17337   operands[0] = gen_lowpart (SImode, operands[0]);
17338   operands[1] = gen_lowpart (SImode, operands[1]);
17339 })
17340
17341 ;; Do not split instructions with mask regs.
17342 (define_split
17343   [(set (match_operand 0 "general_reg_operand")
17344         (not (match_operand 1 "general_reg_operand")))]
17345   "! TARGET_PARTIAL_REG_STALL && reload_completed
17346    && (GET_MODE (operands[0]) == HImode
17347        || (GET_MODE (operands[0]) == QImode
17348            && (TARGET_PROMOTE_QImode
17349                || optimize_insn_for_size_p ())))"
17350   [(set (match_dup 0)
17351         (not:SI (match_dup 1)))]
17352 {
17353   operands[0] = gen_lowpart (SImode, operands[0]);
17354   operands[1] = gen_lowpart (SImode, operands[1]);
17355 })
17356 \f
17357 ;; RTL Peephole optimizations, run before sched2.  These primarily look to
17358 ;; transform a complex memory operation into two memory to register operations.
17359
17360 ;; Don't push memory operands
17361 (define_peephole2
17362   [(set (match_operand:SWI 0 "push_operand")
17363         (match_operand:SWI 1 "memory_operand"))
17364    (match_scratch:SWI 2 "<r>")]
17365   "!(TARGET_PUSH_MEMORY || optimize_insn_for_size_p ())
17366    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
17367   [(set (match_dup 2) (match_dup 1))
17368    (set (match_dup 0) (match_dup 2))])
17369
17370 ;; We need to handle SFmode only, because DFmode and XFmode are split to
17371 ;; SImode pushes.
17372 (define_peephole2
17373   [(set (match_operand:SF 0 "push_operand")
17374         (match_operand:SF 1 "memory_operand"))
17375    (match_scratch:SF 2 "r")]
17376   "!(TARGET_PUSH_MEMORY || optimize_insn_for_size_p ())
17377    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
17378   [(set (match_dup 2) (match_dup 1))
17379    (set (match_dup 0) (match_dup 2))])
17380
17381 ;; Don't move an immediate directly to memory when the instruction
17382 ;; gets too big, or if LCP stalls are a problem for 16-bit moves.
17383 (define_peephole2
17384   [(match_scratch:SWI124 1 "<r>")
17385    (set (match_operand:SWI124 0 "memory_operand")
17386         (const_int 0))]
17387   "optimize_insn_for_speed_p ()
17388    && ((<MODE>mode == HImode
17389        && TARGET_LCP_STALL)
17390        || (!TARGET_USE_MOV0
17391           && TARGET_SPLIT_LONG_MOVES
17392           && get_attr_length (insn) >= ix86_cur_cost ()->large_insn))
17393    && peep2_regno_dead_p (0, FLAGS_REG)"
17394   [(parallel [(set (match_dup 2) (const_int 0))
17395               (clobber (reg:CC FLAGS_REG))])
17396    (set (match_dup 0) (match_dup 1))]
17397   "operands[2] = gen_lowpart (SImode, operands[1]);")
17398
17399 (define_peephole2
17400   [(match_scratch:SWI124 2 "<r>")
17401    (set (match_operand:SWI124 0 "memory_operand")
17402         (match_operand:SWI124 1 "immediate_operand"))]
17403   "optimize_insn_for_speed_p ()
17404    && ((<MODE>mode == HImode
17405        && TARGET_LCP_STALL)
17406        || (TARGET_SPLIT_LONG_MOVES
17407           && get_attr_length (insn) >= ix86_cur_cost ()->large_insn))"
17408   [(set (match_dup 2) (match_dup 1))
17409    (set (match_dup 0) (match_dup 2))])
17410
17411 ;; Don't compare memory with zero, load and use a test instead.
17412 (define_peephole2
17413   [(set (match_operand 0 "flags_reg_operand")
17414         (match_operator 1 "compare_operator"
17415           [(match_operand:SI 2 "memory_operand")
17416            (const_int 0)]))
17417    (match_scratch:SI 3 "r")]
17418   "optimize_insn_for_speed_p () && ix86_match_ccmode (insn, CCNOmode)"
17419   [(set (match_dup 3) (match_dup 2))
17420    (set (match_dup 0) (match_op_dup 1 [(match_dup 3) (const_int 0)]))])
17421
17422 ;; NOT is not pairable on Pentium, while XOR is, but one byte longer.
17423 ;; Don't split NOTs with a displacement operand, because resulting XOR
17424 ;; will not be pairable anyway.
17425 ;;
17426 ;; On AMD K6, NOT is vector decoded with memory operand that cannot be
17427 ;; represented using a modRM byte.  The XOR replacement is long decoded,
17428 ;; so this split helps here as well.
17429 ;;
17430 ;; Note: Can't do this as a regular split because we can't get proper
17431 ;; lifetime information then.
17432
17433 (define_peephole2
17434   [(set (match_operand:SWI124 0 "nonimmediate_gr_operand")
17435         (not:SWI124 (match_operand:SWI124 1 "nonimmediate_gr_operand")))]
17436   "optimize_insn_for_speed_p ()
17437    && ((TARGET_NOT_UNPAIRABLE
17438         && (!MEM_P (operands[0])
17439             || !memory_displacement_operand (operands[0], <MODE>mode)))
17440        || (TARGET_NOT_VECTORMODE
17441            && long_memory_operand (operands[0], <MODE>mode)))
17442    && peep2_regno_dead_p (0, FLAGS_REG)"
17443   [(parallel [(set (match_dup 0)
17444                    (xor:SWI124 (match_dup 1) (const_int -1)))
17445               (clobber (reg:CC FLAGS_REG))])])
17446
17447 ;; Non pairable "test imm, reg" instructions can be translated to
17448 ;; "and imm, reg" if reg dies.  The "and" form is also shorter (one
17449 ;; byte opcode instead of two, have a short form for byte operands),
17450 ;; so do it for other CPUs as well.  Given that the value was dead,
17451 ;; this should not create any new dependencies.  Pass on the sub-word
17452 ;; versions if we're concerned about partial register stalls.
17453
17454 (define_peephole2
17455   [(set (match_operand 0 "flags_reg_operand")
17456         (match_operator 1 "compare_operator"
17457           [(and:SI (match_operand:SI 2 "register_operand")
17458                    (match_operand:SI 3 "immediate_operand"))
17459            (const_int 0)]))]
17460   "ix86_match_ccmode (insn, CCNOmode)
17461    && (true_regnum (operands[2]) != AX_REG
17462        || satisfies_constraint_K (operands[3]))
17463    && peep2_reg_dead_p (1, operands[2])"
17464   [(parallel
17465      [(set (match_dup 0)
17466            (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
17467                             (const_int 0)]))
17468       (set (match_dup 2)
17469            (and:SI (match_dup 2) (match_dup 3)))])])
17470
17471 ;; We don't need to handle HImode case, because it will be promoted to SImode
17472 ;; on ! TARGET_PARTIAL_REG_STALL
17473
17474 (define_peephole2
17475   [(set (match_operand 0 "flags_reg_operand")
17476         (match_operator 1 "compare_operator"
17477           [(and:QI (match_operand:QI 2 "register_operand")
17478                    (match_operand:QI 3 "immediate_operand"))
17479            (const_int 0)]))]
17480   "! TARGET_PARTIAL_REG_STALL
17481    && ix86_match_ccmode (insn, CCNOmode)
17482    && true_regnum (operands[2]) != AX_REG
17483    && peep2_reg_dead_p (1, operands[2])"
17484   [(parallel
17485      [(set (match_dup 0)
17486            (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
17487                             (const_int 0)]))
17488       (set (match_dup 2)
17489            (and:QI (match_dup 2) (match_dup 3)))])])
17490
17491 (define_peephole2
17492   [(set (match_operand 0 "flags_reg_operand")
17493         (match_operator 1 "compare_operator"
17494           [(and:SI
17495              (zero_extract:SI
17496                (match_operand 2 "ext_register_operand")
17497                (const_int 8)
17498                (const_int 8))
17499              (match_operand 3 "const_int_operand"))
17500            (const_int 0)]))]
17501   "! TARGET_PARTIAL_REG_STALL
17502    && ix86_match_ccmode (insn, CCNOmode)
17503    && true_regnum (operands[2]) != AX_REG
17504    && peep2_reg_dead_p (1, operands[2])"
17505   [(parallel [(set (match_dup 0)
17506                    (match_op_dup 1
17507                      [(and:SI
17508                         (zero_extract:SI
17509                           (match_dup 2)
17510                           (const_int 8)
17511                           (const_int 8))
17512                         (match_dup 3))
17513                       (const_int 0)]))
17514               (set (zero_extract:SI (match_dup 2)
17515                                     (const_int 8)
17516                                     (const_int 8))
17517                    (and:SI
17518                      (zero_extract:SI
17519                        (match_dup 2)
17520                        (const_int 8)
17521                        (const_int 8))
17522                      (match_dup 3)))])])
17523
17524 ;; Don't do logical operations with memory inputs.
17525 (define_peephole2
17526   [(match_scratch:SI 2 "r")
17527    (parallel [(set (match_operand:SI 0 "register_operand")
17528                    (match_operator:SI 3 "arith_or_logical_operator"
17529                      [(match_dup 0)
17530                       (match_operand:SI 1 "memory_operand")]))
17531               (clobber (reg:CC FLAGS_REG))])]
17532   "!(TARGET_READ_MODIFY || optimize_insn_for_size_p ())"
17533   [(set (match_dup 2) (match_dup 1))
17534    (parallel [(set (match_dup 0)
17535                    (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
17536               (clobber (reg:CC FLAGS_REG))])])
17537
17538 (define_peephole2
17539   [(match_scratch:SI 2 "r")
17540    (parallel [(set (match_operand:SI 0 "register_operand")
17541                    (match_operator:SI 3 "arith_or_logical_operator"
17542                      [(match_operand:SI 1 "memory_operand")
17543                       (match_dup 0)]))
17544               (clobber (reg:CC FLAGS_REG))])]
17545   "!(TARGET_READ_MODIFY || optimize_insn_for_size_p ())"
17546   [(set (match_dup 2) (match_dup 1))
17547    (parallel [(set (match_dup 0)
17548                    (match_op_dup 3 [(match_dup 2) (match_dup 0)]))
17549               (clobber (reg:CC FLAGS_REG))])])
17550
17551 ;; Prefer Load+RegOp to Mov+MemOp.  Watch out for cases when the memory address
17552 ;; refers to the destination of the load!
17553
17554 (define_peephole2
17555   [(set (match_operand:SI 0 "register_operand")
17556         (match_operand:SI 1 "register_operand"))
17557    (parallel [(set (match_dup 0)
17558                    (match_operator:SI 3 "commutative_operator"
17559                      [(match_dup 0)
17560                       (match_operand:SI 2 "memory_operand")]))
17561               (clobber (reg:CC FLAGS_REG))])]
17562   "REGNO (operands[0]) != REGNO (operands[1])
17563    && GENERAL_REGNO_P (REGNO (operands[0]))
17564    && GENERAL_REGNO_P (REGNO (operands[1]))"
17565   [(set (match_dup 0) (match_dup 4))
17566    (parallel [(set (match_dup 0)
17567                    (match_op_dup 3 [(match_dup 0) (match_dup 1)]))
17568               (clobber (reg:CC FLAGS_REG))])]
17569   "operands[4] = replace_rtx (operands[2], operands[0], operands[1]);")
17570
17571 (define_peephole2
17572   [(set (match_operand 0 "register_operand")
17573         (match_operand 1 "register_operand"))
17574    (set (match_dup 0)
17575                    (match_operator 3 "commutative_operator"
17576                      [(match_dup 0)
17577                       (match_operand 2 "memory_operand")]))]
17578   "REGNO (operands[0]) != REGNO (operands[1])
17579    && ((MMX_REGNO_P (REGNO (operands[0]))
17580         && MMX_REGNO_P (REGNO (operands[1]))) 
17581        || (SSE_REGNO_P (REGNO (operands[0]))
17582            && SSE_REGNO_P (REGNO (operands[1]))))"
17583   [(set (match_dup 0) (match_dup 2))
17584    (set (match_dup 0)
17585         (match_op_dup 3 [(match_dup 0) (match_dup 1)]))])
17586
17587 ; Don't do logical operations with memory outputs
17588 ;
17589 ; These two don't make sense for PPro/PII -- we're expanding a 4-uop
17590 ; instruction into two 1-uop insns plus a 2-uop insn.  That last has
17591 ; the same decoder scheduling characteristics as the original.
17592
17593 (define_peephole2
17594   [(match_scratch:SI 2 "r")
17595    (parallel [(set (match_operand:SI 0 "memory_operand")
17596                    (match_operator:SI 3 "arith_or_logical_operator"
17597                      [(match_dup 0)
17598                       (match_operand:SI 1 "nonmemory_operand")]))
17599               (clobber (reg:CC FLAGS_REG))])]
17600   "!(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17601    /* Do not split stack checking probes.  */
17602    && GET_CODE (operands[3]) != IOR && operands[1] != const0_rtx"
17603   [(set (match_dup 2) (match_dup 0))
17604    (parallel [(set (match_dup 2)
17605                    (match_op_dup 3 [(match_dup 2) (match_dup 1)]))
17606               (clobber (reg:CC FLAGS_REG))])
17607    (set (match_dup 0) (match_dup 2))])
17608
17609 (define_peephole2
17610   [(match_scratch:SI 2 "r")
17611    (parallel [(set (match_operand:SI 0 "memory_operand")
17612                    (match_operator:SI 3 "arith_or_logical_operator"
17613                      [(match_operand:SI 1 "nonmemory_operand")
17614                       (match_dup 0)]))
17615               (clobber (reg:CC FLAGS_REG))])]
17616   "!(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17617    /* Do not split stack checking probes.  */
17618    && GET_CODE (operands[3]) != IOR && operands[1] != const0_rtx"
17619   [(set (match_dup 2) (match_dup 0))
17620    (parallel [(set (match_dup 2)
17621                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
17622               (clobber (reg:CC FLAGS_REG))])
17623    (set (match_dup 0) (match_dup 2))])
17624
17625 ;; Attempt to use arith or logical operations with memory outputs with
17626 ;; setting of flags.
17627 (define_peephole2
17628   [(set (match_operand:SWI 0 "register_operand")
17629         (match_operand:SWI 1 "memory_operand"))
17630    (parallel [(set (match_dup 0)
17631                    (match_operator:SWI 3 "plusminuslogic_operator"
17632                      [(match_dup 0)
17633                       (match_operand:SWI 2 "<nonmemory_operand>")]))
17634               (clobber (reg:CC FLAGS_REG))])
17635    (set (match_dup 1) (match_dup 0))
17636    (set (reg FLAGS_REG) (compare (match_dup 0) (const_int 0)))]
17637   "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17638    && peep2_reg_dead_p (4, operands[0])
17639    && !reg_overlap_mentioned_p (operands[0], operands[1])
17640    && !reg_overlap_mentioned_p (operands[0], operands[2])
17641    && (<MODE>mode != QImode
17642        || immediate_operand (operands[2], QImode)
17643        || q_regs_operand (operands[2], QImode))
17644    && ix86_match_ccmode (peep2_next_insn (3),
17645                          (GET_CODE (operands[3]) == PLUS
17646                           || GET_CODE (operands[3]) == MINUS)
17647                          ? CCGOCmode : CCNOmode)"
17648   [(parallel [(set (match_dup 4) (match_dup 5))
17649               (set (match_dup 1) (match_op_dup 3 [(match_dup 1)
17650                                                   (match_dup 2)]))])]
17651 {
17652   operands[4] = SET_DEST (PATTERN (peep2_next_insn (3)));
17653   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), <MODE>mode,
17654                                 copy_rtx (operands[1]),
17655                                 copy_rtx (operands[2]));
17656   operands[5] = gen_rtx_COMPARE (GET_MODE (operands[4]),
17657                                  operands[5], const0_rtx);
17658 })
17659
17660 (define_peephole2
17661   [(parallel [(set (match_operand:SWI 0 "register_operand")
17662                    (match_operator:SWI 2 "plusminuslogic_operator"
17663                      [(match_dup 0)
17664                       (match_operand:SWI 1 "memory_operand")]))
17665               (clobber (reg:CC FLAGS_REG))])
17666    (set (match_dup 1) (match_dup 0))
17667    (set (reg FLAGS_REG) (compare (match_dup 0) (const_int 0)))]
17668   "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17669    && GET_CODE (operands[2]) != MINUS
17670    && peep2_reg_dead_p (3, operands[0])
17671    && !reg_overlap_mentioned_p (operands[0], operands[1])
17672    && ix86_match_ccmode (peep2_next_insn (2),
17673                          GET_CODE (operands[2]) == PLUS
17674                          ? CCGOCmode : CCNOmode)"
17675   [(parallel [(set (match_dup 3) (match_dup 4))
17676               (set (match_dup 1) (match_op_dup 2 [(match_dup 1)
17677                                                   (match_dup 0)]))])]
17678 {
17679   operands[3] = SET_DEST (PATTERN (peep2_next_insn (2)));
17680   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]), <MODE>mode,
17681                                 copy_rtx (operands[1]),
17682                                 copy_rtx (operands[0]));
17683   operands[4] = gen_rtx_COMPARE (GET_MODE (operands[3]),
17684                                  operands[4], const0_rtx);
17685 })
17686
17687 (define_peephole2
17688   [(set (match_operand:SWI12 0 "register_operand")
17689         (match_operand:SWI12 1 "memory_operand"))
17690    (parallel [(set (match_operand:SI 4 "register_operand")
17691                    (match_operator:SI 3 "plusminuslogic_operator"
17692                      [(match_dup 4)
17693                       (match_operand:SI 2 "nonmemory_operand")]))
17694               (clobber (reg:CC FLAGS_REG))])
17695    (set (match_dup 1) (match_dup 0))
17696    (set (reg FLAGS_REG) (compare (match_dup 0) (const_int 0)))]
17697   "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17698    && REG_P (operands[0]) && REG_P (operands[4])
17699    && REGNO (operands[0]) == REGNO (operands[4])
17700    && peep2_reg_dead_p (4, operands[0])
17701    && (<MODE>mode != QImode
17702        || immediate_operand (operands[2], SImode)
17703        || q_regs_operand (operands[2], SImode))
17704    && !reg_overlap_mentioned_p (operands[0], operands[1])
17705    && !reg_overlap_mentioned_p (operands[0], operands[2])
17706    && ix86_match_ccmode (peep2_next_insn (3),
17707                          (GET_CODE (operands[3]) == PLUS
17708                           || GET_CODE (operands[3]) == MINUS)
17709                          ? CCGOCmode : CCNOmode)"
17710   [(parallel [(set (match_dup 4) (match_dup 5))
17711               (set (match_dup 1) (match_dup 6))])]
17712 {
17713   operands[2] = gen_lowpart (<MODE>mode, operands[2]);
17714   operands[4] = SET_DEST (PATTERN (peep2_next_insn (3)));
17715   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), <MODE>mode,
17716                                 copy_rtx (operands[1]), operands[2]);
17717   operands[5] = gen_rtx_COMPARE (GET_MODE (operands[4]),
17718                                  operands[5], const0_rtx);
17719   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), <MODE>mode,
17720                                 copy_rtx (operands[1]),
17721                                 copy_rtx (operands[2]));
17722 })
17723
17724 ;; Attempt to always use XOR for zeroing registers.
17725 (define_peephole2
17726   [(set (match_operand 0 "register_operand")
17727         (match_operand 1 "const0_operand"))]
17728   "GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
17729    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17730    && GENERAL_REGNO_P (REGNO (operands[0]))
17731    && peep2_regno_dead_p (0, FLAGS_REG)"
17732   [(parallel [(set (match_dup 0) (const_int 0))
17733               (clobber (reg:CC FLAGS_REG))])]
17734   "operands[0] = gen_lowpart (word_mode, operands[0]);")
17735
17736 (define_peephole2
17737   [(set (strict_low_part (match_operand 0 "register_operand"))
17738         (const_int 0))]
17739   "(GET_MODE (operands[0]) == QImode
17740     || GET_MODE (operands[0]) == HImode)
17741    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17742    && peep2_regno_dead_p (0, FLAGS_REG)"
17743   [(parallel [(set (strict_low_part (match_dup 0)) (const_int 0))
17744               (clobber (reg:CC FLAGS_REG))])])
17745
17746 ;; For HI, SI and DI modes, or $-1,reg is smaller than mov $-1,reg.
17747 (define_peephole2
17748   [(set (match_operand:SWI248 0 "register_operand")
17749         (const_int -1))]
17750   "(optimize_insn_for_size_p () || TARGET_MOVE_M1_VIA_OR)
17751    && GENERAL_REGNO_P (REGNO (operands[0]))
17752    && peep2_regno_dead_p (0, FLAGS_REG)"
17753   [(parallel [(set (match_dup 0) (const_int -1))
17754               (clobber (reg:CC FLAGS_REG))])]
17755 {
17756   if (<MODE_SIZE> < GET_MODE_SIZE (SImode))
17757     operands[0] = gen_lowpart (SImode, operands[0]);
17758 })
17759
17760 ;; Attempt to convert simple lea to add/shift.
17761 ;; These can be created by move expanders.
17762 ;; Disable PLUS peepholes on TARGET_OPT_AGU, since all
17763 ;; relevant lea instructions were already split.
17764
17765 (define_peephole2
17766   [(set (match_operand:SWI48 0 "register_operand")
17767         (plus:SWI48 (match_dup 0)
17768                     (match_operand:SWI48 1 "<nonmemory_operand>")))]
17769   "!TARGET_OPT_AGU
17770    && peep2_regno_dead_p (0, FLAGS_REG)"
17771   [(parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (match_dup 1)))
17772               (clobber (reg:CC FLAGS_REG))])])
17773
17774 (define_peephole2
17775   [(set (match_operand:SWI48 0 "register_operand")
17776         (plus:SWI48 (match_operand:SWI48 1 "<nonmemory_operand>")
17777                     (match_dup 0)))]
17778   "!TARGET_OPT_AGU
17779    && peep2_regno_dead_p (0, FLAGS_REG)"
17780   [(parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (match_dup 1)))
17781               (clobber (reg:CC FLAGS_REG))])])
17782
17783 (define_peephole2
17784   [(set (match_operand:DI 0 "register_operand")
17785         (zero_extend:DI
17786           (plus:SI (match_operand:SI 1 "register_operand")
17787                    (match_operand:SI 2 "nonmemory_operand"))))]
17788   "TARGET_64BIT && !TARGET_OPT_AGU
17789    && REGNO (operands[0]) == REGNO (operands[1])
17790    && peep2_regno_dead_p (0, FLAGS_REG)"
17791   [(parallel [(set (match_dup 0)
17792                    (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))
17793               (clobber (reg:CC FLAGS_REG))])])
17794
17795 (define_peephole2
17796   [(set (match_operand:DI 0 "register_operand")
17797         (zero_extend:DI
17798           (plus:SI (match_operand:SI 1 "nonmemory_operand")
17799                    (match_operand:SI 2 "register_operand"))))]
17800   "TARGET_64BIT && !TARGET_OPT_AGU
17801    && REGNO (operands[0]) == REGNO (operands[2])
17802    && peep2_regno_dead_p (0, FLAGS_REG)"
17803   [(parallel [(set (match_dup 0)
17804                    (zero_extend:DI (plus:SI (match_dup 2) (match_dup 1))))
17805               (clobber (reg:CC FLAGS_REG))])])
17806
17807 (define_peephole2
17808   [(set (match_operand:SWI48 0 "register_operand")
17809         (mult:SWI48 (match_dup 0)
17810                     (match_operand:SWI48 1 "const_int_operand")))]
17811   "exact_log2 (INTVAL (operands[1])) >= 0
17812    && peep2_regno_dead_p (0, FLAGS_REG)"
17813   [(parallel [(set (match_dup 0) (ashift:SWI48 (match_dup 0) (match_dup 1)))
17814               (clobber (reg:CC FLAGS_REG))])]
17815   "operands[1] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
17816
17817 (define_peephole2
17818   [(set (match_operand:DI 0 "register_operand")
17819         (zero_extend:DI
17820           (mult:SI (match_operand:SI 1 "register_operand")
17821                    (match_operand:SI 2 "const_int_operand"))))]
17822   "TARGET_64BIT
17823    && exact_log2 (INTVAL (operands[2])) >= 0
17824    && REGNO (operands[0]) == REGNO (operands[1])
17825    && peep2_regno_dead_p (0, FLAGS_REG)"
17826   [(parallel [(set (match_dup 0)
17827                    (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))
17828               (clobber (reg:CC FLAGS_REG))])]
17829   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));")
17830
17831 ;; The ESP adjustments can be done by the push and pop instructions.  Resulting
17832 ;; code is shorter, since push is only 1 byte, while add imm, %esp is 3 bytes.
17833 ;; On many CPUs it is also faster, since special hardware to avoid esp
17834 ;; dependencies is present.
17835
17836 ;; While some of these conversions may be done using splitters, we use
17837 ;; peepholes in order to allow combine_stack_adjustments pass to see
17838 ;; nonobfuscated RTL.
17839
17840 ;; Convert prologue esp subtractions to push.
17841 ;; We need register to push.  In order to keep verify_flow_info happy we have
17842 ;; two choices
17843 ;; - use scratch and clobber it in order to avoid dependencies
17844 ;; - use already live register
17845 ;; We can't use the second way right now, since there is no reliable way how to
17846 ;; verify that given register is live.  First choice will also most likely in
17847 ;; fewer dependencies.  On the place of esp adjustments it is very likely that
17848 ;; call clobbered registers are dead.  We may want to use base pointer as an
17849 ;; alternative when no register is available later.
17850
17851 (define_peephole2
17852   [(match_scratch:W 1 "r")
17853    (parallel [(set (reg:P SP_REG)
17854                    (plus:P (reg:P SP_REG)
17855                            (match_operand:P 0 "const_int_operand")))
17856               (clobber (reg:CC FLAGS_REG))
17857               (clobber (mem:BLK (scratch)))])]
17858   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
17859    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)"
17860   [(clobber (match_dup 1))
17861    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17862               (clobber (mem:BLK (scratch)))])])
17863
17864 (define_peephole2
17865   [(match_scratch:W 1 "r")
17866    (parallel [(set (reg:P SP_REG)
17867                    (plus:P (reg:P SP_REG)
17868                            (match_operand:P 0 "const_int_operand")))
17869               (clobber (reg:CC FLAGS_REG))
17870               (clobber (mem:BLK (scratch)))])]
17871   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
17872    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)"
17873   [(clobber (match_dup 1))
17874    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17875    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17876               (clobber (mem:BLK (scratch)))])])
17877
17878 ;; Convert esp subtractions to push.
17879 (define_peephole2
17880   [(match_scratch:W 1 "r")
17881    (parallel [(set (reg:P SP_REG)
17882                    (plus:P (reg:P SP_REG)
17883                            (match_operand:P 0 "const_int_operand")))
17884               (clobber (reg:CC FLAGS_REG))])]
17885   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
17886    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)"
17887   [(clobber (match_dup 1))
17888    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
17889
17890 (define_peephole2
17891   [(match_scratch:W 1 "r")
17892    (parallel [(set (reg:P SP_REG)
17893                    (plus:P (reg:P SP_REG)
17894                            (match_operand:P 0 "const_int_operand")))
17895               (clobber (reg:CC FLAGS_REG))])]
17896   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
17897    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)"
17898   [(clobber (match_dup 1))
17899    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17900    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
17901
17902 ;; Convert epilogue deallocator to pop.
17903 (define_peephole2
17904   [(match_scratch:W 1 "r")
17905    (parallel [(set (reg:P SP_REG)
17906                    (plus:P (reg:P SP_REG)
17907                            (match_operand:P 0 "const_int_operand")))
17908               (clobber (reg:CC FLAGS_REG))
17909               (clobber (mem:BLK (scratch)))])]
17910   "(TARGET_SINGLE_POP || optimize_insn_for_size_p ())
17911    && INTVAL (operands[0]) == GET_MODE_SIZE (word_mode)"
17912   [(parallel [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17913               (clobber (mem:BLK (scratch)))])])
17914
17915 ;; Two pops case is tricky, since pop causes dependency
17916 ;; on destination register.  We use two registers if available.
17917 (define_peephole2
17918   [(match_scratch:W 1 "r")
17919    (match_scratch:W 2 "r")
17920    (parallel [(set (reg:P SP_REG)
17921                    (plus:P (reg:P SP_REG)
17922                            (match_operand:P 0 "const_int_operand")))
17923               (clobber (reg:CC FLAGS_REG))
17924               (clobber (mem:BLK (scratch)))])]
17925   "(TARGET_DOUBLE_POP || optimize_insn_for_size_p ())
17926    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17927   [(parallel [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17928               (clobber (mem:BLK (scratch)))])
17929    (set (match_dup 2) (mem:W (post_inc:P (reg:P SP_REG))))])
17930
17931 (define_peephole2
17932   [(match_scratch:W 1 "r")
17933    (parallel [(set (reg:P SP_REG)
17934                    (plus:P (reg:P SP_REG)
17935                            (match_operand:P 0 "const_int_operand")))
17936               (clobber (reg:CC FLAGS_REG))
17937               (clobber (mem:BLK (scratch)))])]
17938   "optimize_insn_for_size_p ()
17939    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17940   [(parallel [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17941               (clobber (mem:BLK (scratch)))])
17942    (set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))])
17943
17944 ;; Convert esp additions to pop.
17945 (define_peephole2
17946   [(match_scratch:W 1 "r")
17947    (parallel [(set (reg:P SP_REG)
17948                    (plus:P (reg:P SP_REG)
17949                            (match_operand:P 0 "const_int_operand")))
17950               (clobber (reg:CC FLAGS_REG))])]
17951   "INTVAL (operands[0]) == GET_MODE_SIZE (word_mode)"
17952   [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))])
17953
17954 ;; Two pops case is tricky, since pop causes dependency
17955 ;; on destination register.  We use two registers if available.
17956 (define_peephole2
17957   [(match_scratch:W 1 "r")
17958    (match_scratch:W 2 "r")
17959    (parallel [(set (reg:P SP_REG)
17960                    (plus:P (reg:P SP_REG)
17961                            (match_operand:P 0 "const_int_operand")))
17962               (clobber (reg:CC FLAGS_REG))])]
17963   "INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17964   [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17965    (set (match_dup 2) (mem:W (post_inc:P (reg:P SP_REG))))])
17966
17967 (define_peephole2
17968   [(match_scratch:W 1 "r")
17969    (parallel [(set (reg:P SP_REG)
17970                    (plus:P (reg:P SP_REG)
17971                            (match_operand:P 0 "const_int_operand")))
17972               (clobber (reg:CC FLAGS_REG))])]
17973   "optimize_insn_for_size_p ()
17974    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17975   [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17976    (set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))])
17977 \f
17978 ;; Convert compares with 1 to shorter inc/dec operations when CF is not
17979 ;; required and register dies.  Similarly for 128 to -128.
17980 (define_peephole2
17981   [(set (match_operand 0 "flags_reg_operand")
17982         (match_operator 1 "compare_operator"
17983           [(match_operand 2 "register_operand")
17984            (match_operand 3 "const_int_operand")]))]
17985   "(((!TARGET_FUSE_CMP_AND_BRANCH || optimize_insn_for_size_p ())
17986      && incdec_operand (operands[3], GET_MODE (operands[3])))
17987     || (!TARGET_FUSE_CMP_AND_BRANCH
17988         && INTVAL (operands[3]) == 128))
17989    && ix86_match_ccmode (insn, CCGCmode)
17990    && peep2_reg_dead_p (1, operands[2])"
17991   [(parallel [(set (match_dup 0)
17992                    (match_op_dup 1 [(match_dup 2) (match_dup 3)]))
17993               (clobber (match_dup 2))])])
17994 \f
17995 ;; Convert imul by three, five and nine into lea
17996 (define_peephole2
17997   [(parallel
17998     [(set (match_operand:SWI48 0 "register_operand")
17999           (mult:SWI48 (match_operand:SWI48 1 "register_operand")
18000                       (match_operand:SWI48 2 "const359_operand")))
18001      (clobber (reg:CC FLAGS_REG))])]
18002   "!TARGET_PARTIAL_REG_STALL
18003    || <MODE>mode == SImode
18004    || optimize_function_for_size_p (cfun)"
18005   [(set (match_dup 0)
18006         (plus:SWI48 (mult:SWI48 (match_dup 1) (match_dup 2))
18007                     (match_dup 1)))]
18008   "operands[2] = GEN_INT (INTVAL (operands[2]) - 1);")
18009
18010 (define_peephole2
18011   [(parallel
18012     [(set (match_operand:SWI48 0 "register_operand")
18013           (mult:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
18014                       (match_operand:SWI48 2 "const359_operand")))
18015      (clobber (reg:CC FLAGS_REG))])]
18016   "optimize_insn_for_speed_p ()
18017    && (!TARGET_PARTIAL_REG_STALL || <MODE>mode == SImode)"
18018   [(set (match_dup 0) (match_dup 1))
18019    (set (match_dup 0)
18020         (plus:SWI48 (mult:SWI48 (match_dup 0) (match_dup 2))
18021                     (match_dup 0)))]
18022   "operands[2] = GEN_INT (INTVAL (operands[2]) - 1);")
18023
18024 ;; imul $32bit_imm, mem, reg is vector decoded, while
18025 ;; imul $32bit_imm, reg, reg is direct decoded.
18026 (define_peephole2
18027   [(match_scratch:SWI48 3 "r")
18028    (parallel [(set (match_operand:SWI48 0 "register_operand")
18029                    (mult:SWI48 (match_operand:SWI48 1 "memory_operand")
18030                                (match_operand:SWI48 2 "immediate_operand")))
18031               (clobber (reg:CC FLAGS_REG))])]
18032   "TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
18033    && !satisfies_constraint_K (operands[2])"
18034   [(set (match_dup 3) (match_dup 1))
18035    (parallel [(set (match_dup 0) (mult:SWI48 (match_dup 3) (match_dup 2)))
18036               (clobber (reg:CC FLAGS_REG))])])
18037
18038 (define_peephole2
18039   [(match_scratch:SI 3 "r")
18040    (parallel [(set (match_operand:DI 0 "register_operand")
18041                    (zero_extend:DI
18042                      (mult:SI (match_operand:SI 1 "memory_operand")
18043                               (match_operand:SI 2 "immediate_operand"))))
18044               (clobber (reg:CC FLAGS_REG))])]
18045   "TARGET_64BIT
18046    && TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
18047    && !satisfies_constraint_K (operands[2])"
18048   [(set (match_dup 3) (match_dup 1))
18049    (parallel [(set (match_dup 0)
18050                    (zero_extend:DI (mult:SI (match_dup 3) (match_dup 2))))
18051               (clobber (reg:CC FLAGS_REG))])])
18052
18053 ;; imul $8/16bit_imm, regmem, reg is vector decoded.
18054 ;; Convert it into imul reg, reg
18055 ;; It would be better to force assembler to encode instruction using long
18056 ;; immediate, but there is apparently no way to do so.
18057 (define_peephole2
18058   [(parallel [(set (match_operand:SWI248 0 "register_operand")
18059                    (mult:SWI248
18060                     (match_operand:SWI248 1 "nonimmediate_operand")
18061                     (match_operand:SWI248 2 "const_int_operand")))
18062               (clobber (reg:CC FLAGS_REG))])
18063    (match_scratch:SWI248 3 "r")]
18064   "TARGET_SLOW_IMUL_IMM8 && optimize_insn_for_speed_p ()
18065    && satisfies_constraint_K (operands[2])"
18066   [(set (match_dup 3) (match_dup 2))
18067    (parallel [(set (match_dup 0) (mult:SWI248 (match_dup 0) (match_dup 3)))
18068               (clobber (reg:CC FLAGS_REG))])]
18069 {
18070   if (!rtx_equal_p (operands[0], operands[1]))
18071     emit_move_insn (operands[0], operands[1]);
18072 })
18073
18074 ;; After splitting up read-modify operations, array accesses with memory
18075 ;; operands might end up in form:
18076 ;;  sall    $2, %eax
18077 ;;  movl    4(%esp), %edx
18078 ;;  addl    %edx, %eax
18079 ;; instead of pre-splitting:
18080 ;;  sall    $2, %eax
18081 ;;  addl    4(%esp), %eax
18082 ;; Turn it into:
18083 ;;  movl    4(%esp), %edx
18084 ;;  leal    (%edx,%eax,4), %eax
18085
18086 (define_peephole2
18087   [(match_scratch:W 5 "r")
18088    (parallel [(set (match_operand 0 "register_operand")
18089                    (ashift (match_operand 1 "register_operand")
18090                            (match_operand 2 "const_int_operand")))
18091                (clobber (reg:CC FLAGS_REG))])
18092    (parallel [(set (match_operand 3 "register_operand")
18093                    (plus (match_dup 0)
18094                          (match_operand 4 "x86_64_general_operand")))
18095                    (clobber (reg:CC FLAGS_REG))])]
18096   "IN_RANGE (INTVAL (operands[2]), 1, 3)
18097    /* Validate MODE for lea.  */
18098    && ((!TARGET_PARTIAL_REG_STALL
18099         && (GET_MODE (operands[0]) == QImode
18100             || GET_MODE (operands[0]) == HImode))
18101        || GET_MODE (operands[0]) == SImode
18102        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode))
18103    && (rtx_equal_p (operands[0], operands[3])
18104        || peep2_reg_dead_p (2, operands[0]))
18105    /* We reorder load and the shift.  */
18106    && !reg_overlap_mentioned_p (operands[0], operands[4])"
18107   [(set (match_dup 5) (match_dup 4))
18108    (set (match_dup 0) (match_dup 1))]
18109 {
18110   machine_mode op1mode = GET_MODE (operands[1]);
18111   machine_mode mode = op1mode == DImode ? DImode : SImode;
18112   int scale = 1 << INTVAL (operands[2]);
18113   rtx index = gen_lowpart (word_mode, operands[1]);
18114   rtx base = gen_lowpart (word_mode, operands[5]);
18115   rtx dest = gen_lowpart (mode, operands[3]);
18116
18117   operands[1] = gen_rtx_PLUS (word_mode, base,
18118                               gen_rtx_MULT (word_mode, index, GEN_INT (scale)));
18119   if (mode != word_mode)
18120     operands[1] = gen_rtx_SUBREG (mode, operands[1], 0);
18121
18122   operands[5] = base;
18123   if (op1mode != word_mode)
18124     operands[5] = gen_lowpart (op1mode, operands[5]);
18125
18126   operands[0] = dest;
18127 })
18128 \f
18129 ;; We used to use "int $5", in honor of #BR which maps to interrupt vector 5.
18130 ;; That, however, is usually mapped by the OS to SIGSEGV, which is often
18131 ;; caught for use by garbage collectors and the like.  Using an insn that
18132 ;; maps to SIGILL makes it more likely the program will rightfully die.
18133 ;; Keeping with tradition, "6" is in honor of #UD.
18134 (define_insn "trap"
18135   [(trap_if (const_int 1) (const_int 6))]
18136   ""
18137 {
18138 #ifdef HAVE_AS_IX86_UD2
18139   return "ud2";
18140 #else
18141   return ASM_SHORT "0x0b0f";
18142 #endif
18143 }
18144   [(set_attr "length" "2")])
18145
18146 (define_expand "prefetch"
18147   [(prefetch (match_operand 0 "address_operand")
18148              (match_operand:SI 1 "const_int_operand")
18149              (match_operand:SI 2 "const_int_operand"))]
18150   "TARGET_PREFETCH_SSE || TARGET_PRFCHW || TARGET_PREFETCHWT1"
18151 {
18152   bool write = INTVAL (operands[1]) != 0;
18153   int locality = INTVAL (operands[2]);
18154
18155   gcc_assert (IN_RANGE (locality, 0, 3));
18156
18157   /* Use 3dNOW prefetch in case we are asking for write prefetch not
18158      supported by SSE counterpart or the SSE prefetch is not available
18159      (K6 machines).  Otherwise use SSE prefetch as it allows specifying
18160      of locality.  */
18161   if (TARGET_PREFETCHWT1 && write && locality <= 2)
18162     operands[2] = const2_rtx;
18163   else if (TARGET_PRFCHW && (write || !TARGET_PREFETCH_SSE))
18164     operands[2] = GEN_INT (3);
18165   else
18166     operands[1] = const0_rtx;
18167 })
18168
18169 (define_insn "*prefetch_sse"
18170   [(prefetch (match_operand 0 "address_operand" "p")
18171              (const_int 0)
18172              (match_operand:SI 1 "const_int_operand"))]
18173   "TARGET_PREFETCH_SSE"
18174 {
18175   static const char * const patterns[4] = {
18176    "prefetchnta\t%a0", "prefetcht2\t%a0", "prefetcht1\t%a0", "prefetcht0\t%a0"
18177   };
18178
18179   int locality = INTVAL (operands[1]);
18180   gcc_assert (IN_RANGE (locality, 0, 3));
18181
18182   return patterns[locality];
18183 }
18184   [(set_attr "type" "sse")
18185    (set_attr "atom_sse_attr" "prefetch")
18186    (set (attr "length_address")
18187         (symbol_ref "memory_address_length (operands[0], false)"))
18188    (set_attr "memory" "none")])
18189
18190 (define_insn "*prefetch_3dnow"
18191   [(prefetch (match_operand 0 "address_operand" "p")
18192              (match_operand:SI 1 "const_int_operand" "n")
18193              (const_int 3))]
18194   "TARGET_PRFCHW"
18195 {
18196   if (INTVAL (operands[1]) == 0)
18197     return "prefetch\t%a0";
18198   else
18199     return "prefetchw\t%a0";
18200 }
18201   [(set_attr "type" "mmx")
18202    (set (attr "length_address")
18203         (symbol_ref "memory_address_length (operands[0], false)"))
18204    (set_attr "memory" "none")])
18205
18206 (define_insn "*prefetch_prefetchwt1"
18207   [(prefetch (match_operand 0 "address_operand" "p")
18208              (const_int 1)
18209              (const_int 2))]
18210   "TARGET_PREFETCHWT1"
18211   "prefetchwt1\t%a0";
18212   [(set_attr "type" "sse")
18213    (set (attr "length_address")
18214         (symbol_ref "memory_address_length (operands[0], false)"))
18215    (set_attr "memory" "none")])
18216
18217 (define_expand "stack_protect_set"
18218   [(match_operand 0 "memory_operand")
18219    (match_operand 1 "memory_operand")]
18220   "TARGET_SSP_TLS_GUARD"
18221 {
18222   rtx (*insn)(rtx, rtx);
18223
18224 #ifdef TARGET_THREAD_SSP_OFFSET
18225   operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
18226   insn = (TARGET_LP64
18227           ? gen_stack_tls_protect_set_di
18228           : gen_stack_tls_protect_set_si);
18229 #else
18230   insn = (TARGET_LP64
18231           ? gen_stack_protect_set_di
18232           : gen_stack_protect_set_si);
18233 #endif
18234
18235   emit_insn (insn (operands[0], operands[1]));
18236   DONE;
18237 })
18238
18239 (define_insn "stack_protect_set_<mode>"
18240   [(set (match_operand:PTR 0 "memory_operand" "=m")
18241         (unspec:PTR [(match_operand:PTR 1 "memory_operand" "m")]
18242                     UNSPEC_SP_SET))
18243    (set (match_scratch:PTR 2 "=&r") (const_int 0))
18244    (clobber (reg:CC FLAGS_REG))]
18245   "TARGET_SSP_TLS_GUARD"
18246   "mov{<imodesuffix>}\t{%1, %2|%2, %1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
18247   [(set_attr "type" "multi")])
18248
18249 (define_insn "stack_tls_protect_set_<mode>"
18250   [(set (match_operand:PTR 0 "memory_operand" "=m")
18251         (unspec:PTR [(match_operand:PTR 1 "const_int_operand" "i")]
18252                     UNSPEC_SP_TLS_SET))
18253    (set (match_scratch:PTR 2 "=&r") (const_int 0))
18254    (clobber (reg:CC FLAGS_REG))]
18255   ""
18256   "mov{<imodesuffix>}\t{%@:%P1, %2|%2, <iptrsize> PTR %@:%P1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
18257   [(set_attr "type" "multi")])
18258
18259 (define_expand "stack_protect_test"
18260   [(match_operand 0 "memory_operand")
18261    (match_operand 1 "memory_operand")
18262    (match_operand 2)]
18263   "TARGET_SSP_TLS_GUARD"
18264 {
18265   rtx flags = gen_rtx_REG (CCZmode, FLAGS_REG);
18266
18267   rtx (*insn)(rtx, rtx, rtx);
18268
18269 #ifdef TARGET_THREAD_SSP_OFFSET
18270   operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
18271   insn = (TARGET_LP64
18272           ? gen_stack_tls_protect_test_di
18273           : gen_stack_tls_protect_test_si);
18274 #else
18275   insn = (TARGET_LP64
18276           ? gen_stack_protect_test_di
18277           : gen_stack_protect_test_si);
18278 #endif
18279
18280   emit_insn (insn (flags, operands[0], operands[1]));
18281
18282   emit_jump_insn (gen_cbranchcc4 (gen_rtx_EQ (VOIDmode, flags, const0_rtx),
18283                                   flags, const0_rtx, operands[2]));
18284   DONE;
18285 })
18286
18287 (define_insn "stack_protect_test_<mode>"
18288   [(set (match_operand:CCZ 0 "flags_reg_operand")
18289         (unspec:CCZ [(match_operand:PTR 1 "memory_operand" "m")
18290                      (match_operand:PTR 2 "memory_operand" "m")]
18291                     UNSPEC_SP_TEST))
18292    (clobber (match_scratch:PTR 3 "=&r"))]
18293   "TARGET_SSP_TLS_GUARD"
18294   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
18295   [(set_attr "type" "multi")])
18296
18297 (define_insn "stack_tls_protect_test_<mode>"
18298   [(set (match_operand:CCZ 0 "flags_reg_operand")
18299         (unspec:CCZ [(match_operand:PTR 1 "memory_operand" "m")
18300                      (match_operand:PTR 2 "const_int_operand" "i")]
18301                     UNSPEC_SP_TLS_TEST))
18302    (clobber (match_scratch:PTR 3 "=r"))]
18303   ""
18304   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%@:%P2, %3|%3, <iptrsize> PTR %@:%P2}"
18305   [(set_attr "type" "multi")])
18306
18307 (define_insn "sse4_2_crc32<mode>"
18308   [(set (match_operand:SI 0 "register_operand" "=r")
18309         (unspec:SI
18310           [(match_operand:SI 1 "register_operand" "0")
18311            (match_operand:SWI124 2 "nonimmediate_operand" "<r>m")]
18312           UNSPEC_CRC32))]
18313   "TARGET_SSE4_2 || TARGET_CRC32"
18314   "crc32{<imodesuffix>}\t{%2, %0|%0, %2}"
18315   [(set_attr "type" "sselog1")
18316    (set_attr "prefix_rep" "1")
18317    (set_attr "prefix_extra" "1")
18318    (set (attr "prefix_data16")
18319      (if_then_else (match_operand:HI 2)
18320        (const_string "1")
18321        (const_string "*")))
18322    (set (attr "prefix_rex")
18323      (if_then_else (match_operand:QI 2 "ext_QIreg_operand")
18324        (const_string "1")
18325        (const_string "*")))
18326    (set_attr "mode" "SI")])
18327
18328 (define_insn "sse4_2_crc32di"
18329   [(set (match_operand:DI 0 "register_operand" "=r")
18330         (unspec:DI
18331           [(match_operand:DI 1 "register_operand" "0")
18332            (match_operand:DI 2 "nonimmediate_operand" "rm")]
18333           UNSPEC_CRC32))]
18334   "TARGET_64BIT && (TARGET_SSE4_2 || TARGET_CRC32)"
18335   "crc32{q}\t{%2, %0|%0, %2}"
18336   [(set_attr "type" "sselog1")
18337    (set_attr "prefix_rep" "1")
18338    (set_attr "prefix_extra" "1")
18339    (set_attr "mode" "DI")])
18340
18341 (define_insn "rdpmc"
18342   [(set (match_operand:DI 0 "register_operand" "=A")
18343         (unspec_volatile:DI [(match_operand:SI 1 "register_operand" "c")]
18344                             UNSPECV_RDPMC))]
18345   "!TARGET_64BIT"
18346   "rdpmc"
18347   [(set_attr "type" "other")
18348    (set_attr "length" "2")])
18349
18350 (define_insn "rdpmc_rex64"
18351   [(set (match_operand:DI 0 "register_operand" "=a")
18352         (unspec_volatile:DI [(match_operand:SI 2 "register_operand" "c")]
18353                             UNSPECV_RDPMC))
18354    (set (match_operand:DI 1 "register_operand" "=d")
18355         (unspec_volatile:DI [(match_dup 2)] UNSPECV_RDPMC))]
18356   "TARGET_64BIT"
18357   "rdpmc"
18358   [(set_attr "type" "other")
18359    (set_attr "length" "2")])
18360
18361 (define_insn "rdtsc"
18362   [(set (match_operand:DI 0 "register_operand" "=A")
18363         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
18364   "!TARGET_64BIT"
18365   "rdtsc"
18366   [(set_attr "type" "other")
18367    (set_attr "length" "2")])
18368
18369 (define_insn "rdtsc_rex64"
18370   [(set (match_operand:DI 0 "register_operand" "=a")
18371         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))
18372    (set (match_operand:DI 1 "register_operand" "=d")
18373         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
18374   "TARGET_64BIT"
18375   "rdtsc"
18376   [(set_attr "type" "other")
18377    (set_attr "length" "2")])
18378
18379 (define_insn "rdtscp"
18380   [(set (match_operand:DI 0 "register_operand" "=A")
18381         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18382    (set (match_operand:SI 1 "register_operand" "=c")
18383         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
18384   "!TARGET_64BIT"
18385   "rdtscp"
18386   [(set_attr "type" "other")
18387    (set_attr "length" "3")])
18388
18389 (define_insn "rdtscp_rex64"
18390   [(set (match_operand:DI 0 "register_operand" "=a")
18391         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18392    (set (match_operand:DI 1 "register_operand" "=d")
18393         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18394    (set (match_operand:SI 2 "register_operand" "=c")
18395         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
18396   "TARGET_64BIT"
18397   "rdtscp"
18398   [(set_attr "type" "other")
18399    (set_attr "length" "3")])
18400
18401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18402 ;;
18403 ;; FXSR, XSAVE and XSAVEOPT instructions
18404 ;;
18405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18406
18407 (define_insn "fxsave"
18408   [(set (match_operand:BLK 0 "memory_operand" "=m")
18409         (unspec_volatile:BLK [(const_int 0)] UNSPECV_FXSAVE))]
18410   "TARGET_FXSR"
18411   "fxsave\t%0"
18412   [(set_attr "type" "other")
18413    (set_attr "memory" "store")
18414    (set (attr "length")
18415         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18416
18417 (define_insn "fxsave64"
18418   [(set (match_operand:BLK 0 "memory_operand" "=m")
18419         (unspec_volatile:BLK [(const_int 0)] UNSPECV_FXSAVE64))]
18420   "TARGET_64BIT && TARGET_FXSR"
18421   "fxsave64\t%0"
18422   [(set_attr "type" "other")
18423    (set_attr "memory" "store")
18424    (set (attr "length")
18425         (symbol_ref "ix86_attr_length_address_default (insn) + 4"))])
18426
18427 (define_insn "fxrstor"
18428   [(unspec_volatile [(match_operand:BLK 0 "memory_operand" "m")]
18429                     UNSPECV_FXRSTOR)]
18430   "TARGET_FXSR"
18431   "fxrstor\t%0"
18432   [(set_attr "type" "other")
18433    (set_attr "memory" "load")
18434    (set (attr "length")
18435         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18436
18437 (define_insn "fxrstor64"
18438   [(unspec_volatile [(match_operand:BLK 0 "memory_operand" "m")]
18439                     UNSPECV_FXRSTOR64)]
18440   "TARGET_64BIT && TARGET_FXSR"
18441   "fxrstor64\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) + 4"))])
18446
18447 (define_int_iterator ANY_XSAVE
18448         [UNSPECV_XSAVE
18449          (UNSPECV_XSAVEOPT "TARGET_XSAVEOPT")
18450          (UNSPECV_XSAVEC "TARGET_XSAVEC")
18451          (UNSPECV_XSAVES "TARGET_XSAVES")])
18452
18453 (define_int_iterator ANY_XSAVE64
18454         [UNSPECV_XSAVE64
18455          (UNSPECV_XSAVEOPT64 "TARGET_XSAVEOPT")
18456          (UNSPECV_XSAVEC64 "TARGET_XSAVEC")
18457          (UNSPECV_XSAVES64 "TARGET_XSAVES")])
18458
18459 (define_int_attr xsave
18460         [(UNSPECV_XSAVE "xsave")
18461          (UNSPECV_XSAVE64 "xsave64")
18462          (UNSPECV_XSAVEOPT "xsaveopt")
18463          (UNSPECV_XSAVEOPT64 "xsaveopt64")
18464          (UNSPECV_XSAVEC "xsavec")
18465          (UNSPECV_XSAVEC64 "xsavec64")
18466          (UNSPECV_XSAVES "xsaves")
18467          (UNSPECV_XSAVES64 "xsaves64")])
18468
18469 (define_int_iterator ANY_XRSTOR
18470         [UNSPECV_XRSTOR
18471          (UNSPECV_XRSTORS "TARGET_XSAVES")])
18472
18473 (define_int_iterator ANY_XRSTOR64
18474         [UNSPECV_XRSTOR64
18475          (UNSPECV_XRSTORS64 "TARGET_XSAVES")])
18476
18477 (define_int_attr xrstor
18478         [(UNSPECV_XRSTOR "xrstor")
18479          (UNSPECV_XRSTOR64 "xrstor")
18480          (UNSPECV_XRSTORS "xrstors")
18481          (UNSPECV_XRSTORS64 "xrstors")])
18482
18483 (define_insn "<xsave>"
18484   [(set (match_operand:BLK 0 "memory_operand" "=m")
18485         (unspec_volatile:BLK
18486          [(match_operand:DI 1 "register_operand" "A")]
18487          ANY_XSAVE))]
18488   "!TARGET_64BIT && TARGET_XSAVE"
18489   "<xsave>\t%0"
18490   [(set_attr "type" "other")
18491    (set_attr "memory" "store")
18492    (set (attr "length")
18493         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18494
18495 (define_insn "<xsave>_rex64"
18496   [(set (match_operand:BLK 0 "memory_operand" "=m")
18497         (unspec_volatile:BLK
18498          [(match_operand:SI 1 "register_operand" "a")
18499           (match_operand:SI 2 "register_operand" "d")]
18500          ANY_XSAVE))]
18501   "TARGET_64BIT && TARGET_XSAVE"
18502   "<xsave>\t%0"
18503   [(set_attr "type" "other")
18504    (set_attr "memory" "store")
18505    (set (attr "length")
18506         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18507
18508 (define_insn "<xsave>"
18509   [(set (match_operand:BLK 0 "memory_operand" "=m")
18510         (unspec_volatile:BLK
18511          [(match_operand:SI 1 "register_operand" "a")
18512           (match_operand:SI 2 "register_operand" "d")]
18513          ANY_XSAVE64))]
18514   "TARGET_64BIT && TARGET_XSAVE"
18515   "<xsave>\t%0"
18516   [(set_attr "type" "other")
18517    (set_attr "memory" "store")
18518    (set (attr "length")
18519         (symbol_ref "ix86_attr_length_address_default (insn) + 4"))])
18520
18521 (define_insn "<xrstor>"
18522    [(unspec_volatile:BLK
18523      [(match_operand:BLK 0 "memory_operand" "m")
18524       (match_operand:DI 1 "register_operand" "A")]
18525      ANY_XRSTOR)]
18526   "!TARGET_64BIT && TARGET_XSAVE"
18527   "<xrstor>\t%0"
18528   [(set_attr "type" "other")
18529    (set_attr "memory" "load")
18530    (set (attr "length")
18531         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18532
18533 (define_insn "<xrstor>_rex64"
18534    [(unspec_volatile:BLK
18535      [(match_operand:BLK 0 "memory_operand" "m")
18536       (match_operand:SI 1 "register_operand" "a")
18537       (match_operand:SI 2 "register_operand" "d")]
18538      ANY_XRSTOR)]
18539   "TARGET_64BIT && TARGET_XSAVE"
18540   "<xrstor>\t%0"
18541   [(set_attr "type" "other")
18542    (set_attr "memory" "load")
18543    (set (attr "length")
18544         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18545
18546 (define_insn "<xrstor>64"
18547    [(unspec_volatile:BLK
18548      [(match_operand:BLK 0 "memory_operand" "m")
18549       (match_operand:SI 1 "register_operand" "a")
18550       (match_operand:SI 2 "register_operand" "d")]
18551      ANY_XRSTOR64)]
18552   "TARGET_64BIT && TARGET_XSAVE"
18553   "<xrstor>64\t%0"
18554   [(set_attr "type" "other")
18555    (set_attr "memory" "load")
18556    (set (attr "length")
18557         (symbol_ref "ix86_attr_length_address_default (insn) + 4"))])
18558
18559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18560 ;;
18561 ;; Floating-point instructions for atomic compound assignments
18562 ;;
18563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18564
18565 ; Clobber all floating-point registers on environment save and restore
18566 ; to ensure that the TOS value saved at fnstenv is valid after fldenv.
18567 (define_insn "fnstenv"
18568   [(set (match_operand:BLK 0 "memory_operand" "=m")
18569         (unspec_volatile:BLK [(const_int 0)] UNSPECV_FNSTENV))
18570    (clobber (reg:HI FPCR_REG))
18571    (clobber (reg:XF ST0_REG))
18572    (clobber (reg:XF ST1_REG))
18573    (clobber (reg:XF ST2_REG))
18574    (clobber (reg:XF ST3_REG))
18575    (clobber (reg:XF ST4_REG))
18576    (clobber (reg:XF ST5_REG))
18577    (clobber (reg:XF ST6_REG))
18578    (clobber (reg:XF ST7_REG))]
18579   "TARGET_80387"
18580   "fnstenv\t%0"
18581   [(set_attr "type" "other")
18582    (set_attr "memory" "store")
18583    (set (attr "length")
18584         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))])
18585
18586 (define_insn "fldenv"
18587   [(unspec_volatile [(match_operand:BLK 0 "memory_operand" "m")]
18588                     UNSPECV_FLDENV)
18589    (clobber (reg:CCFP FPSR_REG))
18590    (clobber (reg:HI FPCR_REG))
18591    (clobber (reg:XF ST0_REG))
18592    (clobber (reg:XF ST1_REG))
18593    (clobber (reg:XF ST2_REG))
18594    (clobber (reg:XF ST3_REG))
18595    (clobber (reg:XF ST4_REG))
18596    (clobber (reg:XF ST5_REG))
18597    (clobber (reg:XF ST6_REG))
18598    (clobber (reg:XF ST7_REG))]
18599   "TARGET_80387"
18600   "fldenv\t%0"
18601   [(set_attr "type" "other")
18602    (set_attr "memory" "load")
18603    (set (attr "length")
18604         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))])
18605
18606 (define_insn "fnstsw"
18607   [(set (match_operand:HI 0 "nonimmediate_operand" "=a,m")
18608         (unspec_volatile:HI [(const_int 0)] UNSPECV_FNSTSW))]
18609   "TARGET_80387"
18610   "fnstsw\t%0"
18611   [(set_attr "type" "other,other")
18612    (set_attr "memory" "none,store")
18613    (set (attr "length")
18614         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))])
18615
18616 (define_insn "fnclex"
18617   [(unspec_volatile [(const_int 0)] UNSPECV_FNCLEX)]
18618   "TARGET_80387"
18619   "fnclex"
18620   [(set_attr "type" "other")
18621    (set_attr "memory" "none")
18622    (set_attr "length" "2")])
18623
18624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18625 ;;
18626 ;; LWP instructions
18627 ;;
18628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18629
18630 (define_expand "lwp_llwpcb"
18631   [(unspec_volatile [(match_operand 0 "register_operand" "r")]
18632                     UNSPECV_LLWP_INTRINSIC)]
18633   "TARGET_LWP")
18634
18635 (define_insn "*lwp_llwpcb<mode>1"
18636   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
18637                     UNSPECV_LLWP_INTRINSIC)]
18638   "TARGET_LWP"
18639   "llwpcb\t%0"
18640   [(set_attr "type" "lwp")
18641    (set_attr "mode" "<MODE>")
18642    (set_attr "length" "5")])
18643
18644 (define_expand "lwp_slwpcb"
18645   [(set (match_operand 0 "register_operand" "=r")
18646         (unspec_volatile [(const_int 0)] UNSPECV_SLWP_INTRINSIC))]
18647   "TARGET_LWP"
18648 {
18649   rtx (*insn)(rtx);
18650
18651   insn = (Pmode == DImode
18652           ? gen_lwp_slwpcbdi
18653           : gen_lwp_slwpcbsi);
18654
18655   emit_insn (insn (operands[0]));
18656   DONE;
18657 })
18658
18659 (define_insn "lwp_slwpcb<mode>"
18660   [(set (match_operand:P 0 "register_operand" "=r")
18661         (unspec_volatile:P [(const_int 0)] UNSPECV_SLWP_INTRINSIC))]
18662   "TARGET_LWP"
18663   "slwpcb\t%0"
18664   [(set_attr "type" "lwp")
18665    (set_attr "mode" "<MODE>")
18666    (set_attr "length" "5")])
18667
18668 (define_expand "lwp_lwpval<mode>3"
18669   [(unspec_volatile [(match_operand:SWI48 1 "register_operand" "r")
18670                      (match_operand:SI 2 "nonimmediate_operand" "rm")
18671                      (match_operand:SI 3 "const_int_operand" "i")]
18672                     UNSPECV_LWPVAL_INTRINSIC)]
18673   "TARGET_LWP"
18674   ;; Avoid unused variable warning.
18675   "(void) operands[0];")
18676
18677 (define_insn "*lwp_lwpval<mode>3_1"
18678   [(unspec_volatile [(match_operand:SWI48 0 "register_operand" "r")
18679                      (match_operand:SI 1 "nonimmediate_operand" "rm")
18680                      (match_operand:SI 2 "const_int_operand" "i")]
18681                     UNSPECV_LWPVAL_INTRINSIC)]
18682   "TARGET_LWP"
18683   "lwpval\t{%2, %1, %0|%0, %1, %2}"
18684   [(set_attr "type" "lwp")
18685    (set_attr "mode" "<MODE>")
18686    (set (attr "length")
18687         (symbol_ref "ix86_attr_length_address_default (insn) + 9"))])
18688
18689 (define_expand "lwp_lwpins<mode>3"
18690   [(set (reg:CCC FLAGS_REG)
18691         (unspec_volatile:CCC [(match_operand:SWI48 1 "register_operand" "r")
18692                               (match_operand:SI 2 "nonimmediate_operand" "rm")
18693                               (match_operand:SI 3 "const_int_operand" "i")]
18694                              UNSPECV_LWPINS_INTRINSIC))
18695    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
18696         (eq:QI (reg:CCC FLAGS_REG) (const_int 0)))]
18697   "TARGET_LWP")
18698
18699 (define_insn "*lwp_lwpins<mode>3_1"
18700   [(set (reg:CCC FLAGS_REG)
18701         (unspec_volatile:CCC [(match_operand:SWI48 0 "register_operand" "r")
18702                               (match_operand:SI 1 "nonimmediate_operand" "rm")
18703                               (match_operand:SI 2 "const_int_operand" "i")]
18704                              UNSPECV_LWPINS_INTRINSIC))]
18705   "TARGET_LWP"
18706   "lwpins\t{%2, %1, %0|%0, %1, %2}"
18707   [(set_attr "type" "lwp")
18708    (set_attr "mode" "<MODE>")
18709    (set (attr "length")
18710         (symbol_ref "ix86_attr_length_address_default (insn) + 9"))])
18711
18712 (define_int_iterator RDFSGSBASE
18713         [UNSPECV_RDFSBASE
18714          UNSPECV_RDGSBASE])
18715
18716 (define_int_iterator WRFSGSBASE
18717         [UNSPECV_WRFSBASE
18718          UNSPECV_WRGSBASE])
18719
18720 (define_int_attr fsgs
18721         [(UNSPECV_RDFSBASE "fs")
18722          (UNSPECV_RDGSBASE "gs")
18723          (UNSPECV_WRFSBASE "fs")
18724          (UNSPECV_WRGSBASE "gs")])
18725
18726 (define_insn "rd<fsgs>base<mode>"
18727   [(set (match_operand:SWI48 0 "register_operand" "=r")
18728         (unspec_volatile:SWI48 [(const_int 0)] RDFSGSBASE))]
18729   "TARGET_64BIT && TARGET_FSGSBASE"
18730   "rd<fsgs>base\t%0"
18731   [(set_attr "type" "other")
18732    (set_attr "prefix_extra" "2")])
18733
18734 (define_insn "wr<fsgs>base<mode>"
18735   [(unspec_volatile [(match_operand:SWI48 0 "register_operand" "r")]
18736                     WRFSGSBASE)]
18737   "TARGET_64BIT && TARGET_FSGSBASE"
18738   "wr<fsgs>base\t%0"
18739   [(set_attr "type" "other")
18740    (set_attr "prefix_extra" "2")])
18741
18742 (define_insn "rdrand<mode>_1"
18743   [(set (match_operand:SWI248 0 "register_operand" "=r")
18744         (unspec_volatile:SWI248 [(const_int 0)] UNSPECV_RDRAND))
18745    (set (reg:CCC FLAGS_REG)
18746         (unspec_volatile:CCC [(const_int 0)] UNSPECV_RDRAND))]
18747   "TARGET_RDRND"
18748   "rdrand\t%0"
18749   [(set_attr "type" "other")
18750    (set_attr "prefix_extra" "1")])
18751
18752 (define_insn "rdseed<mode>_1"
18753   [(set (match_operand:SWI248 0 "register_operand" "=r")
18754         (unspec_volatile:SWI248 [(const_int 0)] UNSPECV_RDSEED))
18755    (set (reg:CCC FLAGS_REG)
18756         (unspec_volatile:CCC [(const_int 0)] UNSPECV_RDSEED))]
18757   "TARGET_RDSEED"
18758   "rdseed\t%0"
18759   [(set_attr "type" "other")
18760    (set_attr "prefix_extra" "1")])
18761
18762 (define_expand "pause"
18763   [(set (match_dup 0)
18764         (unspec:BLK [(match_dup 0)] UNSPEC_PAUSE))]
18765   ""
18766 {
18767   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
18768   MEM_VOLATILE_P (operands[0]) = 1;
18769 })
18770
18771 ;; Use "rep; nop", instead of "pause", to support older assemblers.
18772 ;; They have the same encoding.
18773 (define_insn "*pause"
18774   [(set (match_operand:BLK 0)
18775         (unspec:BLK [(match_dup 0)] UNSPEC_PAUSE))]
18776   ""
18777   "rep%; nop"
18778   [(set_attr "length" "2")
18779    (set_attr "memory" "unknown")])
18780
18781 (define_expand "xbegin"
18782   [(set (match_operand:SI 0 "register_operand")
18783         (unspec_volatile:SI [(const_int 0)] UNSPECV_XBEGIN))]
18784   "TARGET_RTM"
18785 {
18786   rtx_code_label *label = gen_label_rtx ();
18787
18788   /* xbegin is emitted as jump_insn, so reload won't be able
18789      to reload its operand.  Force the value into AX hard register.  */
18790   rtx ax_reg = gen_rtx_REG (SImode, AX_REG);
18791   emit_move_insn (ax_reg, constm1_rtx);
18792
18793   emit_jump_insn (gen_xbegin_1 (ax_reg, label));
18794
18795   emit_label (label);
18796   LABEL_NUSES (label) = 1;
18797
18798   emit_move_insn (operands[0], ax_reg);
18799
18800   DONE;
18801 })
18802
18803 (define_insn "xbegin_1"
18804   [(set (pc)
18805         (if_then_else (ne (unspec [(const_int 0)] UNSPEC_XBEGIN_ABORT)
18806                           (const_int 0))
18807                       (label_ref (match_operand 1))
18808                       (pc)))
18809    (set (match_operand:SI 0 "register_operand" "+a")
18810         (unspec_volatile:SI [(match_dup 0)] UNSPECV_XBEGIN))]
18811   "TARGET_RTM"
18812   "xbegin\t%l1"
18813   [(set_attr "type" "other")
18814    (set_attr "length" "6")])
18815
18816 (define_insn "xend"
18817   [(unspec_volatile [(const_int 0)] UNSPECV_XEND)]
18818   "TARGET_RTM"
18819   "xend"
18820   [(set_attr "type" "other")
18821    (set_attr "length" "3")])
18822
18823 (define_insn "xabort"
18824   [(unspec_volatile [(match_operand:SI 0 "const_0_to_255_operand" "n")]
18825                     UNSPECV_XABORT)]
18826   "TARGET_RTM"
18827   "xabort\t%0"
18828   [(set_attr "type" "other")
18829    (set_attr "length" "3")])
18830
18831 (define_expand "xtest"
18832   [(set (match_operand:QI 0 "register_operand")
18833         (unspec_volatile:QI [(const_int 0)] UNSPECV_XTEST))]
18834   "TARGET_RTM"
18835 {
18836   emit_insn (gen_xtest_1 ());
18837
18838   ix86_expand_setcc (operands[0], NE,
18839                      gen_rtx_REG (CCZmode, FLAGS_REG), const0_rtx);
18840   DONE;
18841 })
18842
18843 (define_insn "xtest_1"
18844   [(set (reg:CCZ FLAGS_REG)
18845         (unspec_volatile:CCZ [(const_int 0)] UNSPECV_XTEST))]
18846   "TARGET_RTM"
18847   "xtest"
18848   [(set_attr "type" "other")
18849    (set_attr "length" "3")])
18850
18851 (define_insn "pcommit"
18852   [(unspec_volatile [(const_int 0)] UNSPECV_PCOMMIT)]
18853   "TARGET_PCOMMIT"
18854   "pcommit"
18855   [(set_attr "type" "other")
18856    (set_attr "length" "4")])
18857
18858 (define_insn "clwb"
18859   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
18860                    UNSPECV_CLWB)]
18861   "TARGET_CLWB"
18862   "clwb\t%a0"
18863   [(set_attr "type" "sse")
18864    (set_attr "atom_sse_attr" "fence")
18865    (set_attr "memory" "unknown")])
18866
18867 (define_insn "clflushopt"
18868   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
18869                    UNSPECV_CLFLUSHOPT)]
18870   "TARGET_CLFLUSHOPT"
18871   "clflushopt\t%a0"
18872   [(set_attr "type" "sse")
18873    (set_attr "atom_sse_attr" "fence")
18874    (set_attr "memory" "unknown")])
18875
18876 ;; MONITORX and MWAITX
18877 (define_insn "mwaitx"
18878   [(unspec_volatile [(match_operand:SI 0 "register_operand" "c")
18879                      (match_operand:SI 1 "register_operand" "a")
18880                      (match_operand:SI 2 "register_operand" "b")]
18881                    UNSPECV_MWAITX)]
18882   "TARGET_MWAITX"
18883 ;; 64bit version is "mwaitx %rax,%rcx,%rbx". But only lower 32bits are used.
18884 ;; Since 32bit register operands are implicitly zero extended to 64bit,
18885 ;; we only need to set up 32bit registers.
18886   "mwaitx"
18887   [(set_attr "length" "3")])
18888
18889 (define_insn "monitorx_<mode>"
18890   [(unspec_volatile [(match_operand:P 0 "register_operand" "a")
18891                      (match_operand:SI 1 "register_operand" "c")
18892                      (match_operand:SI 2 "register_operand" "d")]
18893                    UNSPECV_MONITORX)]
18894   "TARGET_MWAITX"
18895 ;; 64bit version is "monitorx %rax,%rcx,%rdx". But only lower 32bits in
18896 ;; RCX and RDX are used.  Since 32bit register operands are implicitly
18897 ;; zero extended to 64bit, we only need to set up 32bit registers.
18898   "%^monitorx"
18899   [(set (attr "length")
18900      (symbol_ref ("(Pmode != word_mode) + 3")))])
18901
18902 ;; MPX instructions
18903
18904 (define_expand "<mode>_mk"
18905   [(set (match_operand:BND 0 "register_operand")
18906     (unspec:BND
18907       [(mem:<bnd_ptr>
18908        (match_par_dup 3
18909         [(match_operand:<bnd_ptr> 1 "register_operand")
18910          (match_operand:<bnd_ptr> 2 "address_mpx_no_base_operand")]))]
18911       UNSPEC_BNDMK))]
18912   "TARGET_MPX"
18913 {
18914   operands[3] = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, operands[1],
18915                                                   operands[2]),
18916                                 UNSPEC_BNDMK_ADDR);
18917 })
18918
18919 (define_insn "*<mode>_mk"
18920   [(set (match_operand:BND 0 "register_operand" "=w")
18921     (unspec:BND
18922       [(match_operator:<bnd_ptr> 3 "bnd_mem_operator"
18923         [(unspec:<bnd_ptr>
18924            [(match_operand:<bnd_ptr> 1 "register_operand" "r")
18925             (match_operand:<bnd_ptr> 2 "address_mpx_no_base_operand" "Tb")]
18926            UNSPEC_BNDMK_ADDR)])]
18927       UNSPEC_BNDMK))]
18928   "TARGET_MPX"
18929   "bndmk\t{%3, %0|%0, %3}"
18930   [(set_attr "type" "mpxmk")])
18931
18932 (define_expand "mov<mode>"
18933   [(set (match_operand:BND 0 "general_operand")
18934         (match_operand:BND 1 "general_operand"))]
18935   "TARGET_MPX"
18936 {
18937   ix86_expand_move (<MODE>mode, operands);DONE;
18938 })
18939
18940 (define_insn "*mov<mode>_internal_mpx"
18941   [(set (match_operand:BND 0 "nonimmediate_operand" "=w,m")
18942         (match_operand:BND 1 "general_operand" "wm,w"))]
18943   "TARGET_MPX"
18944   "bndmov\t{%1, %0|%0, %1}"
18945   [(set_attr "type" "mpxmov")])
18946
18947 (define_expand "<mode>_<bndcheck>"
18948   [(parallel [(unspec [(match_operand:BND 0 "register_operand")
18949                        (match_operand:<bnd_ptr> 1 "address_no_seg_operand")] BNDCHECK)
18950               (set (match_dup 2)
18951                    (unspec:BLK [(match_dup 2)] UNSPEC_MPX_FENCE))])]
18952   "TARGET_MPX"
18953 {
18954   operands[2] = gen_rtx_MEM (BLKmode, operands[1]);
18955   MEM_VOLATILE_P (operands[2]) = 1;
18956 })
18957
18958 (define_insn "*<mode>_<bndcheck>"
18959   [(parallel [(unspec [(match_operand:BND 0 "register_operand" "w")
18960                        (match_operand:<bnd_ptr> 1 "address_no_seg_operand" "Ts")] BNDCHECK)
18961               (set (match_operand:BLK 2 "bnd_mem_operator")
18962                    (unspec:BLK [(match_dup 2)] UNSPEC_MPX_FENCE))])]
18963   "TARGET_MPX"
18964   "bnd<bndcheck>\t{%a1, %0|%0, %a1}"
18965   [(set_attr "type" "mpxchk")])
18966
18967 (define_expand "<mode>_ldx"
18968   [(parallel [(set:BND (match_operand:BND 0 "register_operand")
18969                        (unspec:BND
18970                          [(mem:<bnd_ptr>
18971                            (match_par_dup 3
18972                              [(match_operand:<bnd_ptr> 1 "address_mpx_no_index_operand")
18973                               (match_operand:<bnd_ptr> 2 "register_operand")]))]
18974                          UNSPEC_BNDLDX))
18975               (use (mem:BLK (match_dup 1)))])]
18976   "TARGET_MPX"
18977 {
18978   /* Avoid registers which connot be used as index.  */
18979   if (!index_register_operand (operands[2], Pmode))
18980     {
18981       rtx temp = gen_reg_rtx (Pmode);
18982       emit_move_insn (temp, operands[2]);
18983       operands[2] = temp;
18984     }
18985
18986   /* If it was a register originally then it may have
18987      mode other than Pmode.  We need to extend in such
18988      case because bndldx may work only with Pmode regs.  */
18989   if (GET_MODE (operands[2]) != Pmode)
18990     operands[2] = ix86_zero_extend_to_Pmode (operands[2]);
18991
18992   operands[3] = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, operands[1],
18993                                                   operands[2]),
18994                                 UNSPEC_BNDLDX_ADDR);
18995 })
18996
18997 (define_insn "*<mode>_ldx"
18998   [(parallel [(set:BND (match_operand:BND 0 "register_operand" "=w")
18999                        (unspec:BND
19000                          [(match_operator:<bnd_ptr> 3 "bnd_mem_operator"
19001                            [(unspec:<bnd_ptr>
19002                              [(match_operand:<bnd_ptr> 1 "address_mpx_no_index_operand" "Ti")
19003                               (match_operand:<bnd_ptr> 2 "register_operand" "l")]
19004                             UNSPEC_BNDLDX_ADDR)])]
19005                          UNSPEC_BNDLDX))
19006               (use (mem:BLK (match_dup 1)))])]
19007   "TARGET_MPX"
19008   "bndldx\t{%3, %0|%0, %3}"
19009   [(set_attr "type" "mpxld")])
19010
19011 (define_expand "<mode>_stx"
19012   [(parallel [(unspec [(mem:<bnd_ptr>
19013                          (match_par_dup 3
19014                            [(match_operand:<bnd_ptr> 0 "address_mpx_no_index_operand")
19015                             (match_operand:<bnd_ptr> 1 "register_operand")]))
19016                        (match_operand:BND 2 "register_operand")] UNSPEC_BNDSTX)
19017               (set (match_dup 4)
19018                    (unspec:BLK [(match_dup 4)] UNSPEC_MPX_FENCE))])]
19019   "TARGET_MPX"
19020 {
19021   /* Avoid registers which connot be used as index.  */
19022   if (!index_register_operand (operands[1], Pmode))
19023     {
19024       rtx temp = gen_reg_rtx (Pmode);
19025       emit_move_insn (temp, operands[1]);
19026       operands[1] = temp;
19027     }
19028
19029   /* If it was a register originally then it may have
19030      mode other than Pmode.  We need to extend in such
19031      case because bndstx may work only with Pmode regs.  */
19032   if (GET_MODE (operands[1]) != Pmode)
19033     operands[1] = ix86_zero_extend_to_Pmode (operands[1]);
19034
19035   operands[3] = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, operands[0],
19036                                                   operands[1]),
19037                                 UNSPEC_BNDLDX_ADDR);
19038   operands[4] = gen_rtx_MEM (BLKmode, operands[0]);
19039   MEM_VOLATILE_P (operands[4]) = 1;
19040 })
19041
19042 (define_insn "*<mode>_stx"
19043   [(parallel [(unspec [(match_operator:<bnd_ptr> 3 "bnd_mem_operator"
19044                          [(unspec:<bnd_ptr>
19045                           [(match_operand:<bnd_ptr> 0 "address_mpx_no_index_operand" "Ti")
19046                            (match_operand:<bnd_ptr> 1 "register_operand" "l")]
19047                          UNSPEC_BNDLDX_ADDR)])
19048                        (match_operand:BND 2 "register_operand" "w")] UNSPEC_BNDSTX)
19049               (set (match_operand:BLK 4 "bnd_mem_operator")
19050                    (unspec:BLK [(match_dup 4)] UNSPEC_MPX_FENCE))])]
19051   "TARGET_MPX"
19052   "bndstx\t{%2, %3|%3, %2}"
19053   [(set_attr "type" "mpxst")])
19054
19055 (define_insn "move_size_reloc_<mode>"
19056   [(set (match_operand:SWI48 0 "register_operand" "=r")
19057        (unspec:SWI48
19058         [(match_operand:SWI48 1 "symbol_operand")]
19059         UNSPEC_SIZEOF))]
19060   "TARGET_MPX"
19061 {
19062   if (x86_64_immediate_size_operand (operands[1], VOIDmode))
19063     return "mov{l}\t{%1@SIZE, %k0|%k0, %1@SIZE}";
19064   else
19065     return "movabs{q}\t{%1@SIZE, %0|%0, %1@SIZE}";
19066 }
19067   [(set_attr "type" "imov")
19068    (set_attr "mode" "<MODE>")])
19069
19070 (include "mmx.md")
19071 (include "sse.md")
19072 (include "sync.md")