OSDN Git Service

Emit vzerouppers after reload.
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.md
index 56c2722..278bd77 100644 (file)
@@ -59,6 +59,7 @@
 ;; Y -- print condition for XOP pcom* instruction.
 ;; + -- print a branch hint as 'cs' or 'ds' prefix
 ;; ; -- print a semicolon (after prefixes due to bug in older gas).
+;; @ -- print a segment register of thread base pointer load
 
 ;; UNSPEC usage:
 
@@ -84,6 +85,7 @@
   UNSPEC_SET_RIP
   UNSPEC_SET_GOT_OFFSET
   UNSPEC_MEMORY_BLOCKAGE
+  UNSPEC_STACK_CHECK
 
   ;; TLS support
   UNSPEC_TP
   UNSPEC_REP
   UNSPEC_LD_MPIC       ; load_macho_picbase
   UNSPEC_TRUNC_NOOP
+  UNSPEC_DIV_ALREADY_SPLIT
+  UNSPEC_CALL_NEEDS_VZEROUPPER
 
   ;; For SSE/MMX support:
   UNSPEC_FIX_NOTRUNC
   UNSPEC_PCMPISTR
 
   ;; For FMA4 support
-  UNSPEC_FMA4_INTRINSIC
-  UNSPEC_FMA4_FMADDSUB
-  UNSPEC_FMA4_FMSUBADD
+  UNSPEC_FMADDSUB
   UNSPEC_XOP_UNSIGNED_CMP
   UNSPEC_XOP_TRUEFALSE
   UNSPEC_XOP_PERMUTE
   UNSPECV_LOCK
   UNSPECV_PROLOGUE_USE
   UNSPECV_CLD
+  UNSPECV_NOPS
   UNSPECV_VZEROALL
   UNSPECV_VZEROUPPER
   UNSPECV_RDTSC
   UNSPECV_WRFSBASE
   UNSPECV_WRGSBASE
   UNSPECV_RDRAND
+  UNSPECV_SPLIT_STACK_RETURN
 ])
 
 ;; Constants to represent pcomtrue/pcomfalse variants
 
 ;; Set when REX opcode prefix is used.
 (define_attr "prefix_rex" ""
-  (cond [(ne (symbol_ref "!TARGET_64BIT") (const_int 0))
+  (cond [(eq (symbol_ref "TARGET_64BIT") (const_int 0))
           (const_int 0)
         (and (eq_attr "mode" "DI")
              (and (eq_attr "type" "!push,pop,call,callv,leave,ibr")
 ;; Mapping of unsigned max and min
 (define_code_iterator umaxmin [umax umin])
 
-;; Mapping of signed/unsigned max and min
-(define_code_iterator maxmin [smax smin umax umin])
-
 ;; Base name for integer and FP insn mnemonic
 (define_code_attr maxmin_int [(smax "maxs") (smin "mins")
                              (umax "maxu") (umin "minu")])
 ;; Instruction suffix for integer modes.
 (define_mode_attr imodesuffix [(QI "b") (HI "w") (SI "l") (DI "q")])
 
+;; Pointer size prefix for integer modes (Intel asm dialect)
+(define_mode_attr iptrsize [(QI "BYTE")
+                           (HI "WORD")
+                           (SI "DWORD")
+                           (DI "QWORD")])
+
 ;; Register class for integer modes.
 (define_mode_attr r [(QI "q") (HI "r") (SI "r") (DI "r")])
 
 (include "ppro.md")
 (include "k6.md")
 (include "athlon.md")
+(include "bdver1.md")
 (include "geode.md")
 (include "atom.md")
 
 (define_expand "cmp<mode>_1"
   [(set (reg:CC FLAGS_REG)
        (compare:CC (match_operand:SWI48 0 "nonimmediate_operand" "")
-                   (match_operand:SWI48 1 "<general_operand>" "")))]
-  ""
-  "")
+                   (match_operand:SWI48 1 "<general_operand>" "")))])
 
 (define_insn "*cmp<mode>_ccno_1"
   [(set (reg FLAGS_REG)
              (match_operand 0 "ext_register_operand" "")
              (const_int 8)
              (const_int 8)) 0)
-         (match_operand:QI 1 "immediate_operand" "")))]
-  ""
-  "")
+         (match_operand:QI 1 "immediate_operand" "")))])
 
 (define_insn "*cmpqi_ext_3_insn"
   [(set (reg FLAGS_REG)
   [(set_attr "length" "1")
    (set_attr "athlon_decode" "vector")
    (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "SI")])
 
 ;; Pentium Pro can do steps 1 through 3 in one go.
              ]
              (const_string "0")))
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "double")])
 
 (define_insn "*cmpfp_i_sse"
   [(set (reg:CCFP FLAGS_REG)
                      (const_string "1")
                      (const_string "0")))
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "double")])
 
 (define_insn "*cmpfp_i_i387"
   [(set (reg:CCFP FLAGS_REG)
           ]
           (const_string "XF")))
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "double")])
 
 (define_insn "*cmpfp_iu_mixed"
   [(set (reg:CCFPU FLAGS_REG)
              ]
              (const_string "0")))
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "double")])
 
 (define_insn "*cmpfp_iu_sse"
   [(set (reg:CCFPU FLAGS_REG)
                      (const_string "1")
                      (const_string "0")))
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "double")])
 
 (define_insn "*cmpfp_iu_387"
   [(set (reg:CCFPU FLAGS_REG)
           ]
           (const_string "XF")))
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "direct")])
 \f
 ;; Push/pop instructions.
 
+(define_insn "*push<mode>2"
+  [(set (match_operand:DWI 0 "push_operand" "=<")
+       (match_operand:DWI 1 "general_no_elim_operand" "riF*m"))]
+  ""
+  "#")
+
+(define_split
+  [(set (match_operand:TI 0 "push_operand" "")
+        (match_operand:TI 1 "general_operand" ""))]
+  "TARGET_64BIT && reload_completed
+   && !SSE_REG_P (operands[1])"
+  [(const_int 0)]
+  "ix86_split_long_move (operands); DONE;")
+
 (define_insn "*pushdi2_rex64"
   [(set (match_operand:DI 0 "push_operand" "=<,!<")
        (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
   [(set (match_dup 0) (match_dup 1))
    (set (match_dup 2) (match_dup 3))]
 {
-  split_di (&operands[1], 1, &operands[2], &operands[3]);
+  split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
 
   operands[1] = gen_lowpart (DImode, operands[2]);
   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
   [(set (match_dup 0) (match_dup 1))
    (set (match_dup 2) (match_dup 3))]
 {
-  split_di (&operands[1], 1, &operands[2], &operands[3]);
+  split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
 
   operands[1] = gen_lowpart (DImode, operands[2]);
   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
                                                   GEN_INT (4)));
 })
 
-(define_insn "*pushdi2"
-  [(set (match_operand:DI 0 "push_operand" "=<")
-       (match_operand:DI 1 "general_no_elim_operand" "riF*m"))]
-  "!TARGET_64BIT"
-  "#")
-
 (define_split
   [(set (match_operand:DI 0 "push_operand" "")
         (match_operand:DI 1 "general_operand" ""))]
 ;; "push a byte/word".  But actually we use pushl, which has the effect
 ;; of rounding the amount pushed up to a word.
 
-;; For 64BIT abi we always round up to 8 bytes.
+;; For TARGET_64BIT we always round up to 8 bytes.
 (define_insn "*push<mode>2_rex64"
   [(set (match_operand:SWI124 0 "push_operand" "=X")
        (match_operand:SWI124 1 "nonmemory_no_elim_operand" "r<i>"))]
    && !x86_64_immediate_operand (operands[1], DImode) && 1"
   [(set (match_dup 2) (match_dup 3))
    (set (match_dup 4) (match_dup 5))]
-  "split_di (&operands[0], 2, &operands[2], &operands[4]);")
+  "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
 
 (define_split
   [(set (match_operand:DI 0 "memory_operand" "")
    && !x86_64_immediate_operand (operands[1], DImode)"
   [(set (match_dup 2) (match_dup 3))
    (set (match_dup 4) (match_dup 5))]
-  "split_di (&operands[0], 2, &operands[2], &operands[4]);")
+  "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
 
 (define_insn "*movdi_internal"
   [(set (match_operand:DI 0 "nonimmediate_operand"
    (set_attr "mode" "<MODE>")
    (set_attr "pent_pair" "np")
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "double")])
+   (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "double")])
 
 (define_insn "*swap<mode>_1"
   [(set (match_operand:SWI12 0 "register_operand" "+r")
    (set_attr "mode" "SI")
    (set_attr "pent_pair" "np")
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "double")])
+   (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "double")])
 
 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL
 ;; is disabled for AMDFAM10
   [(set (zero_extract:SWI48 (match_operand 0 "ext_register_operand" "")
                            (const_int 8)
                            (const_int 8))
-       (match_operand:SWI48 1 "nonmemory_operand" ""))]
-  ""
-  "")
+       (match_operand:SWI48 1 "nonmemory_operand" ""))])
 
 (define_insn "*mov<mode>_insv_1_rex64"
   [(set (zero_extract:SWI48x (match_operand 0 "ext_register_operand" "+Q")
 
 (define_split
   [(set (match_operand:TF 0 "push_operand" "")
+       (match_operand:TF 1 "sse_reg_operand" ""))]
+  "TARGET_SSE2 && reload_completed"
+  [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
+   (set (mem:TF (reg:P SP_REG)) (match_dup 1))])
+
+(define_split
+  [(set (match_operand:TF 0 "push_operand" "")
        (match_operand:TF 1 "general_operand" ""))]
   "TARGET_SSE2 && reload_completed
    && !SSE_REG_P (operands[1])"
   [(const_int 0)]
   "ix86_split_long_move (operands); DONE;")
 
-(define_split
-  [(set (match_operand:TF 0 "push_operand" "")
-       (match_operand:TF 1 "any_fp_register_operand" ""))]
-  "TARGET_SSE2"
-  [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
-   (set (mem:TF (reg:P SP_REG)) (match_dup 1))])
-
 (define_insn "*pushxf"
   [(set (match_operand:XF 0 "push_operand" "=<,<")
        (match_operand:XF 1 "general_no_elim_operand" "f,ro"))]
 
 (define_split
   [(set (match_operand:XF 0 "push_operand" "")
-       (match_operand:XF 1 "any_fp_register_operand" ""))]
+       (match_operand:XF 1 "fp_register_operand" ""))]
   "reload_completed"
   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
    (set (mem:XF (reg:P SP_REG)) (match_dup 1))]
   [(set (match_operand:XF 0 "push_operand" "")
        (match_operand:XF 1 "general_operand" ""))]
   "reload_completed
-   && !ANY_FP_REG_P (operands[1])"
+   && !FP_REG_P (operands[1])"
   [(const_int 0)]
   "ix86_split_long_move (operands); DONE;")
 
        (match_operand:XF 1 "general_operand" ""))]
   "reload_completed
    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
-   && ! (ANY_FP_REG_P (operands[0]) ||
+   && ! (FP_REG_P (operands[0]) ||
         (GET_CODE (operands[0]) == SUBREG
-         && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
-   && ! (ANY_FP_REG_P (operands[1]) ||
+         && FP_REG_P (SUBREG_REG (operands[0]))))
+   && ! (FP_REG_P (operands[1]) ||
         (GET_CODE (operands[1]) == SUBREG
-         && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
+         && FP_REG_P (SUBREG_REG (operands[1]))))"
   [(const_int 0)]
   "ix86_split_long_move (operands); DONE;")
 
        (zero_extend:DI (match_dup 0)))]
   "TARGET_64BIT"
   [(set (match_dup 4) (const_int 0))]
-  "split_di (&operands[0], 1, &operands[3], &operands[4]);")
+  "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
 
 ;; %%% Kill me once multi-word ops are sane.
 (define_insn "zero_extendsidi2_1"
   "!TARGET_64BIT && reload_completed
    && true_regnum (operands[0]) == true_regnum (operands[1])"
   [(set (match_dup 4) (const_int 0))]
-  "split_di (&operands[0], 1, &operands[3], &operands[4]);")
+  "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
 
 (define_split
   [(set (match_operand:DI 0 "nonimmediate_operand" "")
    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))"
   [(set (match_dup 3) (match_dup 1))
    (set (match_dup 4) (const_int 0))]
-  "split_di (&operands[0], 1, &operands[3], &operands[4]);")
+  "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
 
 (define_insn "zero_extend<mode>di2"
   [(set (match_operand:DI 0 "register_operand" "=r")
   [(parallel
     [(set (match_operand:SWI24 0 "register_operand" "")
          (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
-     (clobber (reg:CC FLAGS_REG))])]
-  ""
-  "")
+     (clobber (reg:CC FLAGS_REG))])])
 
 (define_insn "*zero_extendqi<mode>2_and"
   [(set (match_operand:SWI24 0 "register_operand" "=r,?&q")
    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
              (clobber (reg:CC FLAGS_REG))])
    (set (match_dup 4) (match_dup 1))]
-  "split_di (&operands[0], 1, &operands[3], &operands[4]);")
+  "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
 
 ;; Extend to memory case when source register does not die.
 (define_split
   "reload_completed"
   [(const_int 0)]
 {
-  split_di (&operands[0], 1, &operands[3], &operands[4]);
+  split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
 
   emit_move_insn (operands[3], operands[1]);
 
   "reload_completed"
   [(const_int 0)]
 {
-  split_di (&operands[0], 1, &operands[3], &operands[4]);
+  split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
 
   if (true_regnum (operands[3]) != true_regnum (operands[1]))
     emit_move_insn (operands[3], operands[1]);
 \f
 ;; Conversions between float and double.
 
-;; These are all no-ops in the model used for the 80387.  So just
-;; emit moves.
+;; These are all no-ops in the model used for the 80387.
+;; So just emit moves.
 
 ;; %%% Kill these when call knows how to work out a DFmode push earlier.
-(define_insn "*dummy_extendsfdf2"
-  [(set (match_operand:DF 0 "push_operand" "=<")
-       (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fY2")))]
-  "0"
-  "#")
-
 (define_split
   [(set (match_operand:DF 0 "push_operand" "")
        (float_extend:DF (match_operand:SF 1 "fp_register_operand" "")))]
-  ""
+  "reload_completed"
   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
    (set (mem:DF (reg:P SP_REG)) (float_extend:DF (match_dup 1)))])
 
-(define_insn "*dummy_extendsfxf2"
-  [(set (match_operand:XF 0 "push_operand" "=<")
-       (float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "f")))]
-  "0"
-  "#")
-
 (define_split
   [(set (match_operand:XF 0 "push_operand" "")
-       (float_extend:XF (match_operand:SF 1 "fp_register_operand" "")))]
-  ""
+       (float_extend:XF (match_operand:MODEF 1 "fp_register_operand" "")))]
+  "reload_completed"
   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
    (set (mem:XF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
 
-(define_split
-  [(set (match_operand:XF 0 "push_operand" "")
-       (float_extend:XF (match_operand:DF 1 "fp_register_operand" "")))]
-  ""
-  [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
-   (set (mem:DF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
-  "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
-
 (define_expand "extendsfdf2"
   [(set (match_operand:DF 0 "nonimmediate_operand" "")
         (float_extend:DF (match_operand:SF 1 "general_operand" "")))]
 (define_expand "truncdfsf2_with_temp"
   [(parallel [(set (match_operand:SF 0 "" "")
                   (float_truncate:SF (match_operand:DF 1 "" "")))
-             (clobber (match_operand:SF 2 "" ""))])]
-  "")
+             (clobber (match_operand:SF 2 "" ""))])])
 
 (define_insn "*truncdfsf_fast_mixed"
   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm,x")
     }
   else
     {
-     enum ix86_stack_slot slot = (virtuals_instantiated
-                                 ? SLOT_TEMP
-                                 : SLOT_VIRTUAL);
+      enum ix86_stack_slot slot = (virtuals_instantiated
+                                  ? SLOT_TEMP
+                                  : SLOT_VIRTUAL);
       operands[2] = assign_386_stack_local (<MODE>mode, slot);
     }
 })
 
   real_ldexp (&TWO31r, &dconst1, 31);
   two31 = const_double_from_real_value (TWO31r, mode);
-  two31 = ix86_build_const_vector (mode, true, two31);
+  two31 = ix86_build_const_vector (vecmode, true, two31);
   operands[2] = force_reg (vecmode, two31);
 })
 
    (set_attr "prefix_rex" "1")
    (set_attr "mode" "<MODE>")
    (set_attr "athlon_decode" "double,vector")
-   (set_attr "amdfam10_decode" "double,double")])
+   (set_attr "amdfam10_decode" "double,double")
+   (set_attr "bdver1_decode" "double,double")])
 
 (define_insn "fix_trunc<mode>si_sse"
   [(set (match_operand:SI 0 "register_operand" "=r,r")
    (set_attr "prefix" "maybe_vex")
    (set_attr "mode" "<MODE>")
    (set_attr "athlon_decode" "double,vector")
-   (set_attr "amdfam10_decode" "double,double")])
+   (set_attr "amdfam10_decode" "double,double")
+   (set_attr "bdver1_decode" "double,double")])
 
 ;; Shorten x87->SSE reload sequences of fix_trunc?f?i_sse patterns.
 (define_peephole2
   [(set (attr "length")
        (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
    (set_attr "mode" "HI")
-   (set_attr "unit" "i387")])
+   (set_attr "unit" "i387")
+   (set_attr "bdver1_decode" "vector")])
 
 (define_insn "x86_fldcw_1"
   [(set (reg:HI FPCR_REG)
    (set_attr "mode" "HI")
    (set_attr "unit" "i387")
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "vector")])
+   (set_attr "amdfam10_decode" "vector")
+   (set_attr "bdver1_decode" "vector")])
 \f
 ;; Conversion between fixed point and floating point.
 
        (float:X87MODEF (match_operand:HI 1 "nonimmediate_operand" "")))]
   "TARGET_80387
    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
-       || TARGET_MIX_SSE_I387)"
-  "")
+       || TARGET_MIX_SSE_I387)")
 
 ;; Pre-reload splitter to add memory clobber to the pattern.
 (define_insn_and_split "*floathi<mode>2_1"
    (set_attr "unit" "*,i387,*,*,*")
    (set_attr "athlon_decode" "*,*,double,direct,double")
    (set_attr "amdfam10_decode" "*,*,vector,double,double")
+   (set_attr "bdver1_decode" "*,*,double,direct,double")
    (set_attr "fp_int_src" "true")])
 
 (define_insn "*floatsi<mode>2_vector_mixed"
    (set_attr "unit" "i387,*")
    (set_attr "athlon_decode" "*,direct")
    (set_attr "amdfam10_decode" "*,double")
+   (set_attr "bdver1_decode" "*,direct")
    (set_attr "fp_int_src" "true")])
 
 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_with_temp"
    (set_attr "unit" "*,i387,*,*")
    (set_attr "athlon_decode" "*,*,double,direct")
    (set_attr "amdfam10_decode" "*,*,vector,double")
+   (set_attr "bdver1_decode" "*,*,double,direct")
    (set_attr "fp_int_src" "true")])
 
 (define_split
    (set_attr "unit" "i387,*,*")
    (set_attr "athlon_decode" "*,double,direct")
    (set_attr "amdfam10_decode" "*,vector,double")
+   (set_attr "bdver1_decode" "*,double,direct")
    (set_attr "fp_int_src" "true")])
 
 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_nointerunit"
        (const_string "*")))
    (set_attr "athlon_decode" "*,direct")
    (set_attr "amdfam10_decode" "*,double")
+   (set_attr "bdver1_decode" "*,direct")
    (set_attr "fp_int_src" "true")])
 
 (define_insn "*floatsi<mode>2_vector_sse_with_temp"
    (set_attr "mode" "<MODE>,<MODE>,<ssevecmode>")
    (set_attr "athlon_decode" "double,direct,double")
    (set_attr "amdfam10_decode" "vector,double,double")
+   (set_attr "bdver1_decode" "double,direct,double")
    (set_attr "fp_int_src" "true")])
 
 (define_insn "*floatsi<mode>2_vector_sse"
    (set_attr "mode" "<MODE>")
    (set_attr "athlon_decode" "direct")
    (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "fp_int_src" "true")])
 
 (define_split
    (set_attr "mode" "<MODEF:MODE>")
    (set_attr "athlon_decode" "double,direct")
    (set_attr "amdfam10_decode" "vector,double")
+   (set_attr "bdver1_decode" "double,direct")
    (set_attr "fp_int_src" "true")])
 
 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_sse_interunit"
        (const_string "*")))
    (set_attr "athlon_decode" "double,direct")
    (set_attr "amdfam10_decode" "vector,double")
+   (set_attr "bdver1_decode" "double,direct")
    (set_attr "fp_int_src" "true")])
 
 (define_split
        (const_string "*")))
    (set_attr "athlon_decode" "direct")
    (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "fp_int_src" "true")])
 
 (define_split
                       (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
                       (match_dup 5))))
              (clobber (reg:CC FLAGS_REG))])]
-  "split_<dwi> (&operands[0], 3, &operands[0], &operands[3]);")
+  "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
 
 (define_insn "*add<mode>3_cc"
   [(set (reg:CC FLAGS_REG)
                       (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
                       (match_dup 5))))
              (clobber (reg:CC FLAGS_REG))])]
-  "split_<dwi> (&operands[0], 3, &operands[0], &operands[3]);")
+  "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
 
 (define_insn "*sub<mode>_1"
   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
                        (const_int 0)])
                      (match_operand:SWI 2 "<general_operand>" ""))))
      (clobber (reg:CC FLAGS_REG))])]
-  "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
-  "")
+  "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)")
 
 (define_insn "*<plusminus_insn><mode>3_carry"
   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
        (plusminus:XF
          (match_operand:XF 1 "register_operand" "")
          (match_operand:XF 2 "register_operand" "")))]
-  "TARGET_80387"
-  "")
+  "TARGET_80387")
 
 (define_expand "<plusminus_insn><mode>3"
   [(set (match_operand:MODEF 0 "register_operand" "")
          (match_operand:MODEF 1 "register_operand" "")
          (match_operand:MODEF 2 "nonimmediate_operand" "")))]
   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
-    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
-  "")
+    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
 \f
 ;; Multiply instructions
 
                   (mult:SWIM248
                     (match_operand:SWIM248 1 "register_operand" "")
                     (match_operand:SWIM248 2 "<general_operand>" "")))
-             (clobber (reg:CC FLAGS_REG))])]
-  ""
-  "")
+             (clobber (reg:CC FLAGS_REG))])])
 
 (define_expand "mulqi3"
   [(parallel [(set (match_operand:QI 0 "register_operand" "")
                     (match_operand:QI 1 "register_operand" "")
                     (match_operand:QI 2 "nonimmediate_operand" "")))
              (clobber (reg:CC FLAGS_REG))])]
-  "TARGET_QIMODE_MATH"
-  "")
+  "TARGET_QIMODE_MATH")
 
 ;; On AMDFAM10
 ;; IMUL reg32/64, reg32/64, imm8       Direct
 ;; IMUL reg32/64, mem32/64, imm32      VectorPath
 ;; IMUL reg32/64, reg32/64             Direct
 ;; IMUL reg32/64, mem32/64             Direct
+;;
+;; On BDVER1, all above IMULs use DirectPath
 
 (define_insn "*mul<mode>3_1"
   [(set (match_operand:SWI48 0 "register_operand" "=r,r,r")
                    (match_operand 1 "memory_operand" ""))
                  (const_string "vector")]
              (const_string "direct")))
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "<MODE>")])
 
 (define_insn "*mulsi3_1_zext"
                    (match_operand 1 "memory_operand" ""))
                  (const_string "vector")]
              (const_string "direct")))
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "SI")])
 
 ;; On AMDFAM10
 ;; IMUL reg16, mem16, imm16    VectorPath
 ;; IMUL reg16, reg16           Direct
 ;; IMUL reg16, mem16           Direct
+;;
+;; On BDVER1, all HI MULs use DoublePath
 
 (define_insn "*mulhi3_1"
   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
        (cond [(eq_attr "alternative" "0,1")
                  (const_string "vector")]
              (const_string "direct")))
+   (set_attr "bdver1_decode" "double")
    (set_attr "mode" "HI")])
 
-;;On AMDFAM10
+;;On AMDFAM10 and BDVER1
 ;; MUL reg8    Direct
 ;; MUL mem8    Direct
 
         (const_string "vector")
         (const_string "direct")))
    (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "QI")])
 
 (define_expand "<u>mul<mode><dwi>3"
                       (match_operand:DWIH 1 "nonimmediate_operand" ""))
                     (any_extend:<DWI>
                       (match_operand:DWIH 2 "register_operand" ""))))
-             (clobber (reg:CC FLAGS_REG))])]
-  ""
-  "")
+             (clobber (reg:CC FLAGS_REG))])])
 
 (define_expand "<u>mulqihi3"
   [(parallel [(set (match_operand:HI 0 "register_operand" "")
                     (any_extend:HI
                       (match_operand:QI 2 "register_operand" ""))))
              (clobber (reg:CC FLAGS_REG))])]
-  "TARGET_QIMODE_MATH"
-  "")
+  "TARGET_QIMODE_MATH")
 
 (define_insn "*<u>mul<mode><dwi>3_1"
   [(set (match_operand:<DWI> 0 "register_operand" "=A")
         (const_string "vector")
         (const_string "double")))
    (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "<MODE>")])
 
 (define_insn "*<u>mulqihi3_1"
         (const_string "vector")
         (const_string "direct")))
    (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "QI")])
 
 (define_expand "<s>mul<mode>3_highpart"
         (const_string "vector")
         (const_string "double")))
    (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "DI")])
 
 (define_insn "*<s>mulsi3_highpart_1"
         (const_string "vector")
         (const_string "double")))
    (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "SI")])
 
 (define_insn "*<s>mulsi3_highpart_zext"
         (const_string "vector")
         (const_string "double")))
    (set_attr "amdfam10_decode" "double")
+   (set_attr "bdver1_decode" "direct")
    (set_attr "mode" "SI")])
 
 ;; The patterns that match these are at the end of this file.
   [(set (match_operand:XF 0 "register_operand" "")
        (mult:XF (match_operand:XF 1 "register_operand" "")
                 (match_operand:XF 2 "register_operand" "")))]
-  "TARGET_80387"
-  "")
+  "TARGET_80387")
 
 (define_expand "mul<mode>3"
   [(set (match_operand:MODEF 0 "register_operand" "")
        (mult:MODEF (match_operand:MODEF 1 "register_operand" "")
                    (match_operand:MODEF 2 "nonimmediate_operand" "")))]
   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
-    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
-  "")
+    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
 \f
 ;; Divide instructions
 
   [(set (match_operand:XF 0 "register_operand" "")
        (div:XF (match_operand:XF 1 "register_operand" "")
                (match_operand:XF 2 "register_operand" "")))]
-  "TARGET_80387"
-  "")
+  "TARGET_80387")
 
 (define_expand "divdf3"
   [(set (match_operand:DF 0 "register_operand" "")
        (div:DF (match_operand:DF 1 "register_operand" "")
                (match_operand:DF 2 "nonimmediate_operand" "")))]
    "(TARGET_80387 && X87_ENABLE_ARITH (DFmode))
-    || (TARGET_SSE2 && TARGET_SSE_MATH)"
-   "")
+    || (TARGET_SSE2 && TARGET_SSE_MATH)")
 
 (define_expand "divsf3"
   [(set (match_operand:SF 0 "register_operand" "")
 \f
 ;; Divmod instructions.
 
+(define_expand "divmod<mode>4"
+  [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
+                  (div:SWIM248
+                    (match_operand:SWIM248 1 "register_operand" "")
+                    (match_operand:SWIM248 2 "nonimmediate_operand" "")))
+             (set (match_operand:SWIM248 3 "register_operand" "")
+                  (mod:SWIM248 (match_dup 1) (match_dup 2)))
+             (clobber (reg:CC FLAGS_REG))])])
+
+;; Split with 8bit unsigned divide:
+;;     if (dividend an divisor are in [0-255])
+;;        use 8bit unsigned integer divide
+;;      else
+;;        use original integer divide
+(define_split
+  [(set (match_operand:SWI48 0 "register_operand" "")
+       (div:SWI48 (match_operand:SWI48 2 "register_operand" "")
+                   (match_operand:SWI48 3 "nonimmediate_operand" "")))
+   (set (match_operand:SWI48 1 "register_operand" "")
+       (mod:SWI48 (match_dup 2) (match_dup 3)))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_USE_8BIT_IDIV
+   && TARGET_QIMODE_MATH
+   && can_create_pseudo_p ()
+   && !optimize_insn_for_size_p ()"
+  [(const_int 0)]
+  "ix86_split_idivmod (<MODE>mode, operands, true); DONE;")
+
+(define_insn_and_split "divmod<mode>4_1"
+  [(set (match_operand:SWI48 0 "register_operand" "=a")
+       (div:SWI48 (match_operand:SWI48 2 "register_operand" "0")
+                  (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
+   (set (match_operand:SWI48 1 "register_operand" "=&d")
+       (mod:SWI48 (match_dup 2) (match_dup 3)))
+   (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
+   (clobber (reg:CC FLAGS_REG))]
+  ""
+  "#"
+  "reload_completed"
+  [(parallel [(set (match_dup 1)
+                  (ashiftrt:SWI48 (match_dup 4) (match_dup 5)))
+             (clobber (reg:CC FLAGS_REG))])
+   (parallel [(set (match_dup 0)
+                  (div:SWI48 (match_dup 2) (match_dup 3)))
+             (set (match_dup 1)
+                  (mod:SWI48 (match_dup 2) (match_dup 3)))
+             (use (match_dup 1))
+             (clobber (reg:CC FLAGS_REG))])]
+{
+  operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
+
+  if (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
+    operands[4] = operands[2];
+  else
+    {
+      /* Avoid use of cltd in favor of a mov+shift.  */
+      emit_move_insn (operands[1], operands[2]);
+      operands[4] = operands[1];
+    }
+}
+  [(set_attr "type" "multi")
+   (set_attr "mode" "<MODE>")])
+
+(define_insn_and_split "*divmod<mode>4"
+  [(set (match_operand:SWIM248 0 "register_operand" "=a")
+       (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
+                   (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
+   (set (match_operand:SWIM248 1 "register_operand" "=&d")
+       (mod:SWIM248 (match_dup 2) (match_dup 3)))
+   (clobber (reg:CC FLAGS_REG))]
+  ""
+  "#"
+  "reload_completed"
+  [(parallel [(set (match_dup 1)
+                  (ashiftrt:SWIM248 (match_dup 4) (match_dup 5)))
+             (clobber (reg:CC FLAGS_REG))])
+   (parallel [(set (match_dup 0)
+                  (div:SWIM248 (match_dup 2) (match_dup 3)))
+             (set (match_dup 1)
+                  (mod:SWIM248 (match_dup 2) (match_dup 3)))
+             (use (match_dup 1))
+             (clobber (reg:CC FLAGS_REG))])]
+{
+  operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
+
+  if (<MODE>mode != HImode
+      && (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD))
+    operands[4] = operands[2];
+  else
+    {
+      /* Avoid use of cltd in favor of a mov+shift.  */
+      emit_move_insn (operands[1], operands[2]);
+      operands[4] = operands[1];
+    }
+}
+  [(set_attr "type" "multi")
+   (set_attr "mode" "<MODE>")])
+
+(define_insn "*divmod<mode>4_noext"
+  [(set (match_operand:SWIM248 0 "register_operand" "=a")
+       (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
+                   (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
+   (set (match_operand:SWIM248 1 "register_operand" "=d")
+       (mod:SWIM248 (match_dup 2) (match_dup 3)))
+   (use (match_operand:SWIM248 4 "register_operand" "1"))
+   (clobber (reg:CC FLAGS_REG))]
+  ""
+  "idiv{<imodesuffix>}\t%3"
+  [(set_attr "type" "idiv")
+   (set_attr "mode" "<MODE>")])
+
 (define_expand "divmodqi4"
   [(parallel [(set (match_operand:QI 0 "register_operand" "")
                   (div:QI
   DONE;
 })
 
-(define_expand "udivmodqi4"
-  [(parallel [(set (match_operand:QI 0 "register_operand" "")
-                  (udiv:QI
-                    (match_operand:QI 1 "register_operand" "")
-                    (match_operand:QI 2 "nonimmediate_operand" "")))
-             (set (match_operand:QI 3 "register_operand" "")
-                  (umod:QI (match_dup 1) (match_dup 2)))
-             (clobber (reg:CC FLAGS_REG))])]
-  "TARGET_QIMODE_MATH"
-{
-  rtx div, mod, insn;
-  rtx tmp0, tmp1;
-  
-  tmp0 = gen_reg_rtx (HImode);
-  tmp1 = gen_reg_rtx (HImode);
-
-  /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
-     in AX.  */
-  emit_insn (gen_zero_extendqihi2 (tmp1, operands[1]));
-  emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, operands[2]));
-
-  /* Extract remainder from AH.  */
-  tmp1 = gen_rtx_ZERO_EXTRACT (SImode, tmp0, GEN_INT (8), GEN_INT (8));
-  tmp1 = simplify_gen_subreg (QImode, tmp1, SImode, 0);
-  insn = emit_move_insn (operands[3], tmp1);
-
-  mod = gen_rtx_UMOD (QImode, operands[1], operands[2]);
-  set_unique_reg_note (insn, REG_EQUAL, mod);
-
-  /* Extract quotient from AL.  */
-  insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
-
-  div = gen_rtx_UDIV (QImode, operands[1], operands[2]);
-  set_unique_reg_note (insn, REG_EQUAL, div);
-
-  DONE;
-})
-
 ;; Divide AX by r/m8, with result stored in
 ;; AL <- Quotient
 ;; AH <- Remainder
   [(set_attr "type" "idiv")
    (set_attr "mode" "QI")])
 
-(define_insn "udivmodhiqi3"
-  [(set (match_operand:HI 0 "register_operand" "=a")
-       (ior:HI
-         (ashift:HI
-           (zero_extend:HI
-             (truncate:QI
-               (mod:HI (match_operand:HI 1 "register_operand" "0")
-                       (zero_extend:HI
-                         (match_operand:QI 2 "nonimmediate_operand" "qm")))))
-           (const_int 8))
-         (zero_extend:HI
-           (truncate:QI
-             (div:HI (match_dup 1) (zero_extend:HI (match_dup 2)))))))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_QIMODE_MATH"
-  "div{b}\t%2"
-  [(set_attr "type" "idiv")
-   (set_attr "mode" "QI")])
-
-(define_expand "divmod<mode>4"
+(define_expand "udivmod<mode>4"
   [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
-                  (div:SWIM248
+                  (udiv:SWIM248
                     (match_operand:SWIM248 1 "register_operand" "")
                     (match_operand:SWIM248 2 "nonimmediate_operand" "")))
              (set (match_operand:SWIM248 3 "register_operand" "")
-                  (mod:SWIM248 (match_dup 1) (match_dup 2)))
-             (clobber (reg:CC FLAGS_REG))])]
-  ""
-  "")
+                  (umod:SWIM248 (match_dup 1) (match_dup 2)))
+             (clobber (reg:CC FLAGS_REG))])])
 
-(define_insn_and_split "*divmod<mode>4"
-  [(set (match_operand:SWIM248 0 "register_operand" "=a")
-       (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
-                   (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
-   (set (match_operand:SWIM248 1 "register_operand" "=&d")
-       (mod:SWIM248 (match_dup 2) (match_dup 3)))
+;; Split with 8bit unsigned divide:
+;;     if (dividend an divisor are in [0-255])
+;;        use 8bit unsigned integer divide
+;;      else
+;;        use original integer divide
+(define_split
+  [(set (match_operand:SWI48 0 "register_operand" "")
+       (udiv:SWI48 (match_operand:SWI48 2 "register_operand" "")
+                   (match_operand:SWI48 3 "nonimmediate_operand" "")))
+   (set (match_operand:SWI48 1 "register_operand" "")
+       (umod:SWI48 (match_dup 2) (match_dup 3)))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_USE_8BIT_IDIV
+   && TARGET_QIMODE_MATH
+   && can_create_pseudo_p ()
+   && !optimize_insn_for_size_p ()"
+  [(const_int 0)]
+  "ix86_split_idivmod (<MODE>mode, operands, false); DONE;")
+
+(define_insn_and_split "udivmod<mode>4_1"
+  [(set (match_operand:SWI48 0 "register_operand" "=a")
+       (udiv:SWI48 (match_operand:SWI48 2 "register_operand" "0")
+                   (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
+   (set (match_operand:SWI48 1 "register_operand" "=&d")
+       (umod:SWI48 (match_dup 2) (match_dup 3)))
+   (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
    (clobber (reg:CC FLAGS_REG))]
   ""
   "#"
   "reload_completed"
-  [(parallel [(set (match_dup 1)
-                  (ashiftrt:SWIM248 (match_dup 4) (match_dup 5)))
-             (clobber (reg:CC FLAGS_REG))])
+  [(set (match_dup 1) (const_int 0))
    (parallel [(set (match_dup 0)
-                  (div:SWIM248 (match_dup 2) (match_dup 3)))
+                  (udiv:SWI48 (match_dup 2) (match_dup 3)))
              (set (match_dup 1)
-                  (mod:SWIM248 (match_dup 2) (match_dup 3)))
+                  (umod:SWI48 (match_dup 2) (match_dup 3)))
              (use (match_dup 1))
              (clobber (reg:CC FLAGS_REG))])]
-{
-  operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
-
-  if (<MODE>mode != HImode
-      && (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD))
-    operands[4] = operands[2];
-  else
-    {
-      /* Avoid use of cltd in favor of a mov+shift.  */
-      emit_move_insn (operands[1], operands[2]);
-      operands[4] = operands[1];
-    }
-}
-  [(set_attr "type" "multi")
-   (set_attr "mode" "<MODE>")])
-
-(define_insn "*divmod<mode>4_noext"
-  [(set (match_operand:SWIM248 0 "register_operand" "=a")
-       (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
-                   (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
-   (set (match_operand:SWIM248 1 "register_operand" "=d")
-       (mod:SWIM248 (match_dup 2) (match_dup 3)))
-   (use (match_operand:SWIM248 4 "register_operand" "1"))
-   (clobber (reg:CC FLAGS_REG))]
   ""
-  "idiv{<imodesuffix>}\t%3"
-  [(set_attr "type" "idiv")
+  [(set_attr "type" "multi")
    (set_attr "mode" "<MODE>")])
 
-(define_expand "udivmod<mode>4"
-  [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
-                  (udiv:SWIM248
-                    (match_operand:SWIM248 1 "register_operand" "")
-                    (match_operand:SWIM248 2 "nonimmediate_operand" "")))
-             (set (match_operand:SWIM248 3 "register_operand" "")
-                  (umod:SWIM248 (match_dup 1) (match_dup 2)))
-             (clobber (reg:CC FLAGS_REG))])]
-  ""
-  "")
-
 (define_insn_and_split "*udivmod<mode>4"
   [(set (match_operand:SWIM248 0 "register_operand" "=a")
        (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
   [(set_attr "type" "idiv")
    (set_attr "mode" "<MODE>")])
 
+(define_expand "udivmodqi4"
+  [(parallel [(set (match_operand:QI 0 "register_operand" "")
+                  (udiv:QI
+                    (match_operand:QI 1 "register_operand" "")
+                    (match_operand:QI 2 "nonimmediate_operand" "")))
+             (set (match_operand:QI 3 "register_operand" "")
+                  (umod:QI (match_dup 1) (match_dup 2)))
+             (clobber (reg:CC FLAGS_REG))])]
+  "TARGET_QIMODE_MATH"
+{
+  rtx div, mod, insn;
+  rtx tmp0, tmp1;
+  
+  tmp0 = gen_reg_rtx (HImode);
+  tmp1 = gen_reg_rtx (HImode);
+
+  /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
+     in AX.  */
+  emit_insn (gen_zero_extendqihi2 (tmp1, operands[1]));
+  emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, operands[2]));
+
+  /* Extract remainder from AH.  */
+  tmp1 = gen_rtx_ZERO_EXTRACT (SImode, tmp0, GEN_INT (8), GEN_INT (8));
+  tmp1 = simplify_gen_subreg (QImode, tmp1, SImode, 0);
+  insn = emit_move_insn (operands[3], tmp1);
+
+  mod = gen_rtx_UMOD (QImode, operands[1], operands[2]);
+  set_unique_reg_note (insn, REG_EQUAL, mod);
+
+  /* Extract quotient from AL.  */
+  insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
+
+  div = gen_rtx_UDIV (QImode, operands[1], operands[2]);
+  set_unique_reg_note (insn, REG_EQUAL, div);
+
+  DONE;
+})
+
+(define_insn "udivmodhiqi3"
+  [(set (match_operand:HI 0 "register_operand" "=a")
+       (ior:HI
+         (ashift:HI
+           (zero_extend:HI
+             (truncate:QI
+               (mod:HI (match_operand:HI 1 "register_operand" "0")
+                       (zero_extend:HI
+                         (match_operand:QI 2 "nonimmediate_operand" "qm")))))
+           (const_int 8))
+         (zero_extend:HI
+           (truncate:QI
+             (div:HI (match_dup 1) (zero_extend:HI (match_dup 2)))))))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_QIMODE_MATH"
+  "div{b}\t%2"
+  [(set_attr "type" "idiv")
+   (set_attr "mode" "QI")])
+
 ;; We cannot use div/idiv for double division, because it causes
 ;; "division by zero" on the overflow and that's not what we expect
 ;; from truncate.  Because true (non truncating) double division is
        (compare:CCNO
          (and:SI (match_operand:SI 0 "nonimmediate_operand" "")
                  (match_operand:SI 1 "nonmemory_operand" ""))
-         (const_int 0)))]
-  ""
-  "")
+         (const_int 0)))])
 
 (define_expand "testqi_ccz_1"
   [(set (reg:CCZ FLAGS_REG)
         (compare:CCZ (and:QI (match_operand:QI 0 "nonimmediate_operand" "")
                             (match_operand:QI 1 "nonmemory_operand" ""))
-                (const_int 0)))]
-  ""
-  "")
+                (const_int 0)))])
+
+(define_expand "testdi_ccno_1"
+  [(set (reg:CCNO FLAGS_REG)
+       (compare:CCNO
+         (and:DI (match_operand:DI 0 "nonimmediate_operand" "")
+                 (match_operand:DI 1 "x86_64_szext_general_operand" ""))
+         (const_int 0)))]
+  "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))")
 
 (define_insn "*testdi_1"
   [(set (reg FLAGS_REG)
              (const_int 8)
              (const_int 8))
            (match_operand 1 "const_int_operand" ""))
-         (const_int 0)))]
-  ""
-  "")
+         (const_int 0)))])
 
 (define_insn "*testqi_ext_0"
   [(set (reg FLAGS_REG)
             (match_dup 1)
             (const_int 8)
             (const_int 8))
-           (match_dup 2)))])]
-  ""
-  "")
+           (match_dup 2)))])])
 
 (define_insn "*xorqi_cc_ext_1_rex64"
   [(set (reg FLAGS_REG)
     [(set (match_dup 2)
          (neg:DWIH (match_dup 2)))
      (clobber (reg:CC FLAGS_REG))])]
-  "split_<dwi> (&operands[0], 2, &operands[0], &operands[2]);")
+  "split_double_mode (<DWI>mode, &operands[0], 2, &operands[0], &operands[2]);")
 
 (define_insn "*neg<mode>2_1"
   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
    (set_attr "prefix_0f" "1")
    (set_attr "mode" "DI")
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "vector")])
+   (set_attr "amdfam10_decode" "vector")
+   (set_attr "bdver1_decode" "vector")])
 
 (define_insn "x86_shld"
   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
    (set_attr "mode" "SI")
    (set_attr "pent_pair" "np")
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "vector")])
+   (set_attr "amdfam10_decode" "vector")
+   (set_attr "bdver1_decode" "vector")])
 
 (define_expand "x86_shift<mode>_adj_1"
   [(set (reg:CCZ FLAGS_REG)
   DONE;
 })
 
+;; Avoid useless masking of count operand.
+(define_insn_and_split "*ashl<mode>3_mask"
+  [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
+       (ashift:SWI48
+         (match_operand:SWI48 1 "nonimmediate_operand" "0")
+         (subreg:QI
+           (and:SI
+             (match_operand:SI 2 "nonimmediate_operand" "c")
+             (match_operand:SI 3 "const_int_operand" "n")) 0)))
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)
+   && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
+      == GET_MODE_BITSIZE (<MODE>mode)-1"
+  "#"
+  "&& 1"
+  [(parallel [(set (match_dup 0)
+                  (ashift:SWI48 (match_dup 1) (match_dup 2)))
+             (clobber (reg:CC FLAGS_REG))])]
+{
+  if (can_create_pseudo_p ())
+    operands [2] = force_reg (SImode, operands[2]);
+
+  operands[2] = simplify_gen_subreg (QImode, operands[2], SImode, 0);
+}
+  [(set_attr "type" "ishift")
+   (set_attr "mode" "<MODE>")])
+
 (define_insn "*ashl<mode>3_1"
   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
        (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,l")
   ""
   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
 
+;; Avoid useless masking of count operand.
+(define_insn_and_split "*<shiftrt_insn><mode>3_mask"
+  [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
+       (any_shiftrt:SWI48
+         (match_operand:SWI48 1 "nonimmediate_operand" "0")
+         (subreg:QI
+           (and:SI
+             (match_operand:SI 2 "nonimmediate_operand" "c")
+             (match_operand:SI 3 "const_int_operand" "n")) 0)))
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
+   && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
+      == GET_MODE_BITSIZE (<MODE>mode)-1"
+  "#"
+  "&& 1"
+  [(parallel [(set (match_dup 0)
+                  (any_shiftrt:SWI48 (match_dup 1) (match_dup 2)))
+             (clobber (reg:CC FLAGS_REG))])]
+{
+  if (can_create_pseudo_p ())
+    operands [2] = force_reg (SImode, operands[2]);
+
+  operands[2] = simplify_gen_subreg (QImode, operands[2], SImode, 0);
+}
+  [(set_attr "type" "ishift")
+   (set_attr "mode" "<MODE>")])
+
 (define_insn_and_split "*<shiftrt_insn><mode>3_doubleword"
   [(set (match_operand:DWI 0 "register_operand" "=r")
        (any_shiftrt:DWI (match_operand:DWI 1 "register_operand" "0")
    (set_attr "prefix_0f" "1")
    (set_attr "mode" "DI")
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "vector")])
+   (set_attr "amdfam10_decode" "vector")
+   (set_attr "bdver1_decode" "vector")])
 
 (define_insn "x86_shrd"
   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
    (set_attr "mode" "SI")
    (set_attr "pent_pair" "np")
    (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "vector")])
+   (set_attr "amdfam10_decode" "vector")
+   (set_attr "bdver1_decode" "vector")])
 
 (define_insn "ashrdi3_cvt"
   [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
   ""
   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
 
+;; Avoid useless masking of count operand.
+(define_insn_and_split "*<rotate_insn><mode>3_mask"
+  [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
+       (any_rotate:SWI48
+         (match_operand:SWI48 1 "nonimmediate_operand" "0")
+         (subreg:QI
+           (and:SI
+             (match_operand:SI 2 "nonimmediate_operand" "c")
+             (match_operand:SI 3 "const_int_operand" "n")) 0)))
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
+   && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
+      == GET_MODE_BITSIZE (<MODE>mode)-1"
+  "#"
+  "&& 1"
+  [(parallel [(set (match_dup 0)
+                  (any_rotate:SWI48 (match_dup 1) (match_dup 2)))
+             (clobber (reg:CC FLAGS_REG))])]
+{
+  if (can_create_pseudo_p ())
+    operands [2] = force_reg (SImode, operands[2]);
+
+  operands[2] = simplify_gen_subreg (QImode, operands[2], SImode, 0);
+}
+  [(set_attr "type" "rotate")
+   (set_attr "mode" "<MODE>")])
+
 ;; Implement rotation using two double-precision
 ;; shift instructions and a scratch register.
 
 {
   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
 
-  split_<dwi> (&operands[0], 1, &operands[4], &operands[5]);
+  split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
 })
 
 (define_insn_and_split "ix86_rotr<dwi>3_doubleword"
 {
   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
 
-  split_<dwi> (&operands[0], 1, &operands[4], &operands[5]);
+  split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
 })
 
 (define_insn "*<rotate_insn><mode>3_1"
   DONE;
 })
 
+(define_insn_and_split "*call_pop_0_vzeroupper"
+  [(call (mem:QI (match_operand:SI 0 "constant_call_address_operand" ""))
+        (match_operand:SI 1 "" ""))
+   (set (reg:SI SP_REG)
+       (plus:SI (reg:SI SP_REG)
+                (match_operand:SI 2 "immediate_operand" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_pop_vzeroupper (curr_insn, operands[3]); DONE;"
+  [(set_attr "type" "call")])
+
 (define_insn "*call_pop_0"
   [(call (mem:QI (match_operand:SI 0 "constant_call_address_operand" ""))
         (match_operand:SI 1 "" ""))
 }
   [(set_attr "type" "call")])
 
+(define_insn_and_split "*call_pop_1_vzeroupper"
+  [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
+        (match_operand:SI 1 "" ""))
+   (set (reg:SI SP_REG)
+       (plus:SI (reg:SI SP_REG)
+                (match_operand:SI 2 "immediate_operand" "i")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_pop_vzeroupper (curr_insn, operands[3]); DONE;"
+  [(set_attr "type" "call")])
+
 (define_insn "*call_pop_1"
   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
         (match_operand:SI 1 "" ""))
 }
   [(set_attr "type" "call")])
 
+(define_insn_and_split "*sibcall_pop_1_vzeroupper"
+  [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
+        (match_operand:SI 1 "" ""))
+   (set (reg:SI SP_REG)
+       (plus:SI (reg:SI SP_REG)
+                (match_operand:SI 2 "immediate_operand" "i,i")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_pop_vzeroupper (curr_insn, operands[3]); DONE;"
+  [(set_attr "type" "call")])
+
 (define_insn "*sibcall_pop_1"
   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
         (match_operand:SI 1 "" ""))
   DONE;
 })
 
+(define_insn_and_split "*call_0_vzeroupper"
+  [(call (mem:QI (match_operand 0 "constant_call_address_operand" ""))
+        (match_operand 1 "" ""))
+   (unspec [(match_operand 2 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
+  [(set_attr "type" "call")])
+
 (define_insn "*call_0"
   [(call (mem:QI (match_operand 0 "constant_call_address_operand" ""))
         (match_operand 1 "" ""))]
   ""
-{
-  if (SIBLING_CALL_P (insn))
-    return "jmp\t%P0";
-  else
-    return "call\t%P0";
-}
+  { return ix86_output_call_insn (insn, operands[0], 0); }
+  [(set_attr "type" "call")])
+
+(define_insn_and_split "*call_1_vzeroupper"
+  [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
+        (match_operand 1 "" ""))
+   (unspec [(match_operand 2 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
   [(set_attr "type" "call")])
 
 (define_insn "*call_1"
   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
         (match_operand 1 "" ""))]
   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
-{
-  if (constant_call_address_operand (operands[0], Pmode))
-    return "call\t%P0";
-  return "call\t%A0";
-}
+  { return ix86_output_call_insn (insn, operands[0], 0); }
+  [(set_attr "type" "call")])
+
+(define_insn_and_split "*sibcall_1_vzeroupper"
+  [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
+        (match_operand 1 "" ""))
+   (unspec [(match_operand 2 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
   [(set_attr "type" "call")])
 
 (define_insn "*sibcall_1"
   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
         (match_operand 1 "" ""))]
   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
-  "@
-   jmp\t%P0
-   jmp\t%A0"
+  { return ix86_output_call_insn (insn, operands[0], 0); }
+  [(set_attr "type" "call")])
+
+(define_insn_and_split "*call_1_rex64_vzeroupper"
+  [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
+        (match_operand 1 "" ""))
+   (unspec [(match_operand 2 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)
+   && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
   [(set_attr "type" "call")])
 
 (define_insn "*call_1_rex64"
         (match_operand 1 "" ""))]
   "TARGET_64BIT && !SIBLING_CALL_P (insn)
    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
-{
-  if (constant_call_address_operand (operands[0], Pmode))
-    return "call\t%P0";
-  return "call\t%A0";
-}
+  { return ix86_output_call_insn (insn, operands[0], 0); }
+  [(set_attr "type" "call")])
+
+(define_insn_and_split "*call_1_rex64_ms_sysv_vzeroupper"
+  [(parallel
+    [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
+          (match_operand 1 "" ""))
+     (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
+     (clobber (reg:TI XMM6_REG))
+     (clobber (reg:TI XMM7_REG))
+     (clobber (reg:TI XMM8_REG))
+     (clobber (reg:TI XMM9_REG))
+     (clobber (reg:TI XMM10_REG))
+     (clobber (reg:TI XMM11_REG))
+     (clobber (reg:TI XMM12_REG))
+     (clobber (reg:TI XMM13_REG))
+     (clobber (reg:TI XMM14_REG))
+     (clobber (reg:TI XMM15_REG))
+     (clobber (reg:DI SI_REG))
+     (clobber (reg:DI DI_REG))])
+   (unspec [(match_operand 2 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
   [(set_attr "type" "call")])
 
 (define_insn "*call_1_rex64_ms_sysv"
    (clobber (reg:DI SI_REG))
    (clobber (reg:DI DI_REG))]
   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
-{
-  if (constant_call_address_operand (operands[0], Pmode))
-    return "call\t%P0";
-  return "call\t%A0";
-}
+  { return ix86_output_call_insn (insn, operands[0], 0); }
+  [(set_attr "type" "call")])
+
+(define_insn_and_split "*call_1_rex64_large_vzeroupper"
+  [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rm"))
+        (match_operand 1 "" ""))
+   (unspec [(match_operand 2 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
   [(set_attr "type" "call")])
 
 (define_insn "*call_1_rex64_large"
   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rm"))
         (match_operand 1 "" ""))]
   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
-  "call\t%A0"
+  { return ix86_output_call_insn (insn, operands[0], 0); }
   [(set_attr "type" "call")])
 
-(define_insn "*sibcall_1_rex64"
+(define_insn_and_split "*sibcall_1_rex64_vzeroupper"
   [(call (mem:QI (match_operand:DI 0 "sibcall_insn_operand" "s,U"))
-        (match_operand 1 "" ""))]
-  "TARGET_64BIT && SIBLING_CALL_P (insn)"
-  "@
-   jmp\t%P0
-   jmp\t%A0"
+        (match_operand 1 "" ""))
+   (unspec [(match_operand 2 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
+  [(set_attr "type" "call")])
+
+(define_insn "*sibcall_1_rex64"
+  [(call (mem:QI (match_operand:DI 0 "sibcall_insn_operand" "s,U"))
+        (match_operand 1 "" ""))]
+  "TARGET_64BIT && SIBLING_CALL_P (insn)"
+  { return ix86_output_call_insn (insn, operands[0], 0); }
   [(set_attr "type" "call")])
 
 ;; Call subroutine, returning value in operand 0
    (set_attr "length_immediate" "0")
    (set_attr "modrm" "0")])
 
+;; Generate nops.  Operand 0 is the number of nops, up to 8.
+(define_insn "nops"
+  [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
+                   UNSPECV_NOPS)]
+  "reload_completed"
+{
+  int num = INTVAL (operands[0]);
+
+  gcc_assert (num >= 1 && num <= 8);
+
+  while (num--)
+    fputs ("\tnop\n", asm_out_file);
+
+  return "";
+}
+  [(set (attr "length") (symbol_ref "INTVAL (operands[0])"))
+   (set_attr "length_immediate" "0")
+   (set_attr "modrm" "0")])
+
 ;; Pad to 16-byte boundary, max skip in op0.  Used to avoid
 ;; branch prediction penalty for the third jump in a 16-byte
 ;; block on K8.
        (unspec:SI [(const_int 0)] UNSPEC_SET_GOT))
    (clobber (reg:CC FLAGS_REG))]
   "!TARGET_64BIT"
-  { return output_set_got (operands[0], NULL_RTX); }
+  "* return output_set_got (operands[0], NULL_RTX);"
   [(set_attr "type" "multi")
    (set_attr "length" "12")])
 
         UNSPEC_SET_GOT))
    (clobber (reg:CC FLAGS_REG))]
   "!TARGET_64BIT"
-  { return output_set_got (operands[0], operands[1]); }
+  "* return output_set_got (operands[0], operands[1]);"
   [(set_attr "type" "multi")
    (set_attr "length" "12")])
 
   "leave"
   [(set_attr "type" "leave")])
 \f
+;; Handle -fsplit-stack.
+
+(define_expand "split_stack_prologue"
+  [(const_int 0)]
+  ""
+{
+  ix86_expand_split_stack_prologue ();
+  DONE;
+})
+
+;; In order to support the call/return predictor, we use a return
+;; instruction which the middle-end doesn't see.
+(define_insn "split_stack_return"
+  [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "")]
+                    UNSPECV_SPLIT_STACK_RETURN)]
+  ""
+{
+  if (operands[0] == const0_rtx)
+    return "ret";
+  else
+    return "ret\t%0";
+}
+  [(set_attr "atom_unit" "jeu")
+   (set_attr "modrm" "0")
+   (set (attr "length")
+       (if_then_else (match_operand:SI 0 "const0_operand" "")
+                     (const_int 1)
+                     (const_int 3)))
+   (set (attr "length_immediate")
+       (if_then_else (match_operand:SI 0 "const0_operand" "")
+                     (const_int 0)
+                     (const_int 2)))])
+
+;; If there are operand 0 bytes available on the stack, jump to
+;; operand 1.
+
+(define_expand "split_stack_space_check"
+  [(set (pc) (if_then_else
+             (ltu (minus (reg SP_REG)
+                         (match_operand 0 "register_operand" ""))
+                  (unspec [(const_int 0)] UNSPEC_STACK_CHECK))
+             (label_ref (match_operand 1 "" ""))
+             (pc)))]
+  ""
+{
+  rtx reg, size, limit;
+
+  reg = gen_reg_rtx (Pmode);
+  size = force_reg (Pmode, operands[0]);
+  emit_insn (gen_sub3_insn (reg, stack_pointer_rtx, size));
+  limit = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
+                         UNSPEC_STACK_CHECK);
+  limit = gen_rtx_MEM (Pmode, gen_rtx_CONST (Pmode, limit));
+  ix86_expand_branch (GEU, reg, limit, operands[1]);
+
+  DONE;
+})
+\f
 ;; Bit manipulation instructions.
 
 (define_expand "ffs<mode>2"
                              UNSPEC_TLS_GD))
              (clobber (match_dup 4))
              (clobber (match_dup 5))
-             (clobber (reg:CC FLAGS_REG))])]
-  "")
-
-;; Load and add the thread base pointer from %gs:0.
-
-(define_insn "*load_tp_si"
-  [(set (match_operand:SI 0 "register_operand" "=r")
-       (unspec:SI [(const_int 0)] UNSPEC_TP))]
-  "!TARGET_64BIT"
-  "mov{l}\t{%%gs:0, %0|%0, DWORD PTR gs:0}"
-  [(set_attr "type" "imov")
-   (set_attr "modrm" "0")
-   (set_attr "length" "7")
-   (set_attr "memory" "load")
-   (set_attr "imm_disp" "false")])
+             (clobber (reg:CC FLAGS_REG))])])
 
-(define_insn "*add_tp_si"
-  [(set (match_operand:SI 0 "register_operand" "=r")
-       (plus:SI (unspec:SI [(const_int 0)] UNSPEC_TP)
-                (match_operand:SI 1 "register_operand" "0")))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT"
-  "add{l}\t{%%gs:0, %0|%0, DWORD PTR gs:0}"
-  [(set_attr "type" "alu")
-   (set_attr "modrm" "0")
-   (set_attr "length" "7")
-   (set_attr "memory" "load")
-   (set_attr "imm_disp" "false")])
+;; Segment register for the thread base ptr load
+(define_mode_attr tp_seg [(SI "gs") (DI "fs")])
 
-(define_insn "*load_tp_di"
-  [(set (match_operand:DI 0 "register_operand" "=r")
-       (unspec:DI [(const_int 0)] UNSPEC_TP))]
-  "TARGET_64BIT"
-  "mov{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}"
+;; Load and add the thread base pointer from %gs:0.
+(define_insn "*load_tp_<mode>"
+  [(set (match_operand:P 0 "register_operand" "=r")
+       (unspec:P [(const_int 0)] UNSPEC_TP))]
+  ""
+  "mov{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
   [(set_attr "type" "imov")
    (set_attr "modrm" "0")
    (set_attr "length" "7")
    (set_attr "memory" "load")
    (set_attr "imm_disp" "false")])
 
-(define_insn "*add_tp_di"
-  [(set (match_operand:DI 0 "register_operand" "=r")
-       (plus:DI (unspec:DI [(const_int 0)] UNSPEC_TP)
-                (match_operand:DI 1 "register_operand" "0")))
+(define_insn "*add_tp_<mode>"
+  [(set (match_operand:P 0 "register_operand" "=r")
+       (plus:P (unspec:P [(const_int 0)] UNSPEC_TP)
+               (match_operand:P 1 "register_operand" "0")))
    (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT"
-  "add{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}"
+  ""
+  "add{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
   [(set_attr "type" "alu")
    (set_attr "modrm" "0")
    (set_attr "length" "7")
   operands[4] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
   emit_insn (gen_tls_dynamic_gnu2_64 (operands[4], operands[1]));
 })
-
-;;
 \f
 ;; These patterns match the binary 387 instructions for addM3, subM3,
 ;; mulM3 and divM3.  There are three patterns for each of DFmode and
   [(set_attr "type" "fpspc")
    (set_attr "mode" "XF")
    (set_attr "athlon_decode" "direct")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "direct")])
 
 (define_insn "sqrt_extend<mode>xf2_i387"
   [(set (match_operand:XF 0 "register_operand" "=f")
   [(set_attr "type" "fpspc")
    (set_attr "mode" "XF")
    (set_attr "athlon_decode" "direct")
-   (set_attr "amdfam10_decode" "direct")])
+   (set_attr "amdfam10_decode" "direct")
+   (set_attr "bdver1_decode" "direct")])
 
 (define_insn "*rsqrtsf2_sse"
   [(set (match_operand:SF 0 "register_operand" "=x")
    (set_attr "prefix" "maybe_vex")
    (set_attr "mode" "<MODE>")
    (set_attr "athlon_decode" "*")
-   (set_attr "amdfam10_decode" "*")])
+   (set_attr "amdfam10_decode" "*")
+   (set_attr "bdver1_decode" "*")])
 
 (define_expand "sqrt<mode>2"
   [(set (match_operand:MODEF 0 "register_operand" "")
                              UNSPEC_FPATAN))
              (clobber (match_scratch:XF 3 ""))])]
   "TARGET_USE_FANCY_MATH_387
-   && flag_unsafe_math_optimizations"
-  "")
+   && flag_unsafe_math_optimizations")
 
 (define_expand "atan2<mode>3"
   [(use (match_operand:MODEF 0 "register_operand" ""))
                   (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
   "TARGET_USE_FANCY_MATH_387
    && flag_unsafe_math_optimizations"
-{
-  operands[2] = gen_reg_rtx (XFmode);
-})
+  "operands[2] = gen_reg_rtx (XFmode);")
 
 (define_expand "logb<mode>2"
   [(use (match_operand:MODEF 0 "register_operand" ""))
                   (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
   "TARGET_USE_FANCY_MATH_387
    && flag_unsafe_math_optimizations"
-{
-  operands[2] = gen_reg_rtx (XFmode);
-})
+  "operands[2] = gen_reg_rtx (XFmode);")
 
 (define_expand "significand<mode>2"
   [(use (match_operand:MODEF 0 "register_operand" ""))
   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
      (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
                      UNSPEC_FIST))]
-  "TARGET_USE_FANCY_MATH_387"
-  "")
+  "TARGET_USE_FANCY_MATH_387")
 
 (define_expand "lrint<MODEF:mode><SSEMODEI24:mode>2"
   [(set (match_operand:SSEMODEI24 0 "nonimmediate_operand" "")
      (unspec:SSEMODEI24 [(match_operand:MODEF 1 "register_operand" "")]
                        UNSPEC_FIX_NOTRUNC))]
   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
-   && ((<SSEMODEI24:MODE>mode != DImode) || TARGET_64BIT)"
-  "")
+   && ((<SSEMODEI24:MODE>mode != DImode) || TARGET_64BIT)")
 
 (define_expand "lround<MODEF:mode><SSEMODEI24:mode>2"
   [(match_operand:SSEMODEI24 0 "nonimmediate_operand" "")
              (clobber (reg:CC FLAGS_REG))])]
   "TARGET_USE_FANCY_MATH_387
    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
-   && flag_unsafe_math_optimizations"
-  "")
+   && flag_unsafe_math_optimizations")
 
 (define_expand "lfloor<MODEF:mode><SWI48:mode>2"
   [(match_operand:SWI48 0 "nonimmediate_operand" "")
              (clobber (reg:CC FLAGS_REG))])]
   "TARGET_USE_FANCY_MATH_387
    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
-   && flag_unsafe_math_optimizations"
-  "")
+   && flag_unsafe_math_optimizations")
 
 (define_expand "lceil<MODEF:mode><SWI48:mode>2"
   [(match_operand:SWI48 0 "nonimmediate_operand" "")
    && flag_unsafe_math_optimizations"
 {
   emit_insn (gen_frndintxf2_mask_pm (operands[0], operands[1]));
-
   DONE;
 })
 
   DONE;
 })
 
-(define_expand "signbit<mode>2"
+(define_expand "signbitxf2"
+  [(use (match_operand:SI 0 "register_operand" ""))
+   (use (match_operand:XF 1 "register_operand" ""))]
+  "TARGET_USE_FANCY_MATH_387"
+{
+  rtx scratch = gen_reg_rtx (HImode);
+
+  emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
+  emit_insn (gen_andsi3 (operands[0],
+            gen_lowpart (SImode, scratch), GEN_INT (0x200)));
+  DONE;
+})
+
+(define_insn "movmsk_df"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+       (unspec:SI
+         [(match_operand:DF 1 "register_operand" "x")]
+         UNSPEC_MOVMSK))]
+  "SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH"
+  "%vmovmskpd\t{%1, %0|%0, %1}"
+  [(set_attr "type" "ssemov")
+   (set_attr "prefix" "maybe_vex")
+   (set_attr "mode" "DF")])
+
+;; Use movmskpd in SSE mode to avoid store forwarding stall
+;; for 32bit targets and movq+shrq sequence for 64bit targets.
+(define_expand "signbitdf2"
   [(use (match_operand:SI 0 "register_operand" ""))
-   (use (match_operand:X87MODEF 1 "register_operand" ""))]
+   (use (match_operand:DF 1 "register_operand" ""))]
   "TARGET_USE_FANCY_MATH_387
-   && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
+   || (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)"
 {
-  rtx mask = GEN_INT (0x0200);
+  if (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)
+    {
+      emit_insn (gen_movmsk_df (operands[0], operands[1]));
+      emit_insn (gen_andsi3 (operands[0], operands[0], const1_rtx));
+    }
+  else
+    {
+      rtx scratch = gen_reg_rtx (HImode);
+
+      emit_insn (gen_fxamdf2_i387 (scratch, operands[1]));
+      emit_insn (gen_andsi3 (operands[0],
+                gen_lowpart (SImode, scratch), GEN_INT (0x200)));
+    }
+  DONE;
+})
 
+(define_expand "signbitsf2"
+  [(use (match_operand:SI 0 "register_operand" ""))
+   (use (match_operand:SF 1 "register_operand" ""))]
+  "TARGET_USE_FANCY_MATH_387
+   && !(SSE_FLOAT_MODE_P (SFmode) && TARGET_SSE_MATH)"
+{
   rtx scratch = gen_reg_rtx (HImode);
 
-  emit_insn (gen_fxam<mode>2_i387 (scratch, operands[1]));
-  emit_insn (gen_andsi3 (operands[0], gen_lowpart (SImode, scratch), mask));
+  emit_insn (gen_fxamsf2_i387 (scratch, operands[1]));
+  emit_insn (gen_andsi3 (operands[0],
+            gen_lowpart (SImode, scratch), GEN_INT (0x200)));
   DONE;
 })
 \f
    (set_attr "length_immediate" "0")
    (set_attr "modrm" "0")])
 
-(define_expand "movmemsi"
+(define_expand "movmem<mode>"
   [(use (match_operand:BLK 0 "memory_operand" ""))
    (use (match_operand:BLK 1 "memory_operand" ""))
-   (use (match_operand:SI 2 "nonmemory_operand" ""))
-   (use (match_operand:SI 3 "const_int_operand" ""))
+   (use (match_operand:SWI48 2 "nonmemory_operand" ""))
+   (use (match_operand:SWI48 3 "const_int_operand" ""))
    (use (match_operand:SI 4 "const_int_operand" ""))
    (use (match_operand:SI 5 "const_int_operand" ""))]
   ""
    FAIL;
 })
 
-(define_expand "movmemdi"
-  [(use (match_operand:BLK 0 "memory_operand" ""))
-   (use (match_operand:BLK 1 "memory_operand" ""))
-   (use (match_operand:DI 2 "nonmemory_operand" ""))
-   (use (match_operand:DI 3 "const_int_operand" ""))
-   (use (match_operand:SI 4 "const_int_operand" ""))
-   (use (match_operand:SI 5 "const_int_operand" ""))]
-  "TARGET_64BIT"
-{
- if (ix86_expand_movmem (operands[0], operands[1], operands[2], operands[3],
-                        operands[4], operands[5]))
-   DONE;
- else
-   FAIL;
-})
-
 ;; Most CPUs don't like single string operations
 ;; Handle this case here to simplify previous expander.
 
   "TARGET_64BIT"
   "movsq"
   [(set_attr "type" "str")
-   (set_attr "mode" "DI")
-   (set_attr "memory" "both")])
+   (set_attr "memory" "both")
+   (set_attr "mode" "DI")])
 
 (define_insn "*strmovsi_1"
-  [(set (mem:SI (match_operand:SI 2 "register_operand" "0"))
-       (mem:SI (match_operand:SI 3 "register_operand" "1")))
-   (set (match_operand:SI 0 "register_operand" "=D")
-       (plus:SI (match_dup 2)
-                (const_int 4)))
-   (set (match_operand:SI 1 "register_operand" "=S")
-       (plus:SI (match_dup 3)
-                (const_int 4)))]
-  "!TARGET_64BIT"
-  "movs{l|d}"
-  [(set_attr "type" "str")
-   (set_attr "mode" "SI")
-   (set_attr "memory" "both")])
-
-(define_insn "*strmovsi_rex_1"
-  [(set (mem:SI (match_operand:DI 2 "register_operand" "0"))
-       (mem:SI (match_operand:DI 3 "register_operand" "1")))
-   (set (match_operand:DI 0 "register_operand" "=D")
-       (plus:DI (match_dup 2)
-                (const_int 4)))
-   (set (match_operand:DI 1 "register_operand" "=S")
-       (plus:DI (match_dup 3)
-                (const_int 4)))]
-  "TARGET_64BIT"
+  [(set (mem:SI (match_operand:P 2 "register_operand" "0"))
+       (mem:SI (match_operand:P 3 "register_operand" "1")))
+   (set (match_operand:P 0 "register_operand" "=D")
+       (plus:P (match_dup 2)
+               (const_int 4)))
+   (set (match_operand:P 1 "register_operand" "=S")
+       (plus:P (match_dup 3)
+               (const_int 4)))]
+  ""
   "movs{l|d}"
   [(set_attr "type" "str")
-   (set_attr "mode" "SI")
-   (set_attr "memory" "both")])
-
-(define_insn "*strmovhi_1"
-  [(set (mem:HI (match_operand:SI 2 "register_operand" "0"))
-       (mem:HI (match_operand:SI 3 "register_operand" "1")))
-   (set (match_operand:SI 0 "register_operand" "=D")
-       (plus:SI (match_dup 2)
-                (const_int 2)))
-   (set (match_operand:SI 1 "register_operand" "=S")
-       (plus:SI (match_dup 3)
-                (const_int 2)))]
-  "!TARGET_64BIT"
-  "movsw"
-  [(set_attr "type" "str")
    (set_attr "memory" "both")
-   (set_attr "mode" "HI")])
+   (set_attr "mode" "SI")])
 
-(define_insn "*strmovhi_rex_1"
-  [(set (mem:HI (match_operand:DI 2 "register_operand" "0"))
-       (mem:HI (match_operand:DI 3 "register_operand" "1")))
-   (set (match_operand:DI 0 "register_operand" "=D")
-       (plus:DI (match_dup 2)
-                (const_int 2)))
-   (set (match_operand:DI 1 "register_operand" "=S")
-       (plus:DI (match_dup 3)
-                (const_int 2)))]
-  "TARGET_64BIT"
+(define_insn "*strmovhi_1"
+  [(set (mem:HI (match_operand:P 2 "register_operand" "0"))
+       (mem:HI (match_operand:P 3 "register_operand" "1")))
+   (set (match_operand:P 0 "register_operand" "=D")
+       (plus:P (match_dup 2)
+               (const_int 2)))
+   (set (match_operand:P 1 "register_operand" "=S")
+       (plus:P (match_dup 3)
+               (const_int 2)))]
+  ""
   "movsw"
   [(set_attr "type" "str")
    (set_attr "memory" "both")
    (set_attr "mode" "HI")])
 
 (define_insn "*strmovqi_1"
-  [(set (mem:QI (match_operand:SI 2 "register_operand" "0"))
-       (mem:QI (match_operand:SI 3 "register_operand" "1")))
-   (set (match_operand:SI 0 "register_operand" "=D")
-       (plus:SI (match_dup 2)
-                (const_int 1)))
-   (set (match_operand:SI 1 "register_operand" "=S")
-       (plus:SI (match_dup 3)
-                (const_int 1)))]
-  "!TARGET_64BIT"
-  "movsb"
-  [(set_attr "type" "str")
-   (set_attr "memory" "both")
-   (set_attr "mode" "QI")])
-
-(define_insn "*strmovqi_rex_1"
-  [(set (mem:QI (match_operand:DI 2 "register_operand" "0"))
-       (mem:QI (match_operand:DI 3 "register_operand" "1")))
-   (set (match_operand:DI 0 "register_operand" "=D")
-       (plus:DI (match_dup 2)
-                (const_int 1)))
-   (set (match_operand:DI 1 "register_operand" "=S")
-       (plus:DI (match_dup 3)
-                (const_int 1)))]
-  "TARGET_64BIT"
+  [(set (mem:QI (match_operand:P 2 "register_operand" "0"))
+       (mem:QI (match_operand:P 3 "register_operand" "1")))
+   (set (match_operand:P 0 "register_operand" "=D")
+       (plus:P (match_dup 2)
+               (const_int 1)))
+   (set (match_operand:P 1 "register_operand" "=S")
+       (plus:P (match_dup 3)
+               (const_int 1)))]
+  ""
   "movsb"
   [(set_attr "type" "str")
    (set_attr "memory" "both")
-   (set_attr "prefix_rex" "0")
+   (set (attr "prefix_rex")
+       (if_then_else
+         (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
+         (const_string "0")
+         (const_string "*")))
    (set_attr "mode" "QI")])
 
 (define_expand "rep_mov"
    (set_attr "mode" "DI")])
 
 (define_insn "*rep_movsi"
-  [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
-   (set (match_operand:SI 0 "register_operand" "=D")
-        (plus:SI (ashift:SI (match_operand:SI 5 "register_operand" "2")
-                           (const_int 2))
-                (match_operand:SI 3 "register_operand" "0")))
-   (set (match_operand:SI 1 "register_operand" "=S")
-        (plus:SI (ashift:SI (match_dup 5) (const_int 2))
-                (match_operand:SI 4 "register_operand" "1")))
-   (set (mem:BLK (match_dup 3))
-       (mem:BLK (match_dup 4)))
-   (use (match_dup 5))]
-  "!TARGET_64BIT"
-  "rep{%;} movs{l|d}"
-  [(set_attr "type" "str")
-   (set_attr "prefix_rep" "1")
-   (set_attr "memory" "both")
-   (set_attr "mode" "SI")])
-
-(define_insn "*rep_movsi_rex64"
-  [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
-   (set (match_operand:DI 0 "register_operand" "=D")
-        (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
-                           (const_int 2))
-                (match_operand:DI 3 "register_operand" "0")))
-   (set (match_operand:DI 1 "register_operand" "=S")
-        (plus:DI (ashift:DI (match_dup 5) (const_int 2))
-                (match_operand:DI 4 "register_operand" "1")))
+  [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
+   (set (match_operand:P 0 "register_operand" "=D")
+        (plus:P (ashift:P (match_operand:P 5 "register_operand" "2")
+                         (const_int 2))
+                (match_operand:P 3 "register_operand" "0")))
+   (set (match_operand:P 1 "register_operand" "=S")
+        (plus:P (ashift:P (match_dup 5) (const_int 2))
+               (match_operand:P 4 "register_operand" "1")))
    (set (mem:BLK (match_dup 3))
        (mem:BLK (match_dup 4)))
    (use (match_dup 5))]
-  "TARGET_64BIT"
+  ""
   "rep{%;} movs{l|d}"
   [(set_attr "type" "str")
    (set_attr "prefix_rep" "1")
    (set_attr "mode" "SI")])
 
 (define_insn "*rep_movqi"
-  [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
-   (set (match_operand:SI 0 "register_operand" "=D")
-        (plus:SI (match_operand:SI 3 "register_operand" "0")
-                (match_operand:SI 5 "register_operand" "2")))
-   (set (match_operand:SI 1 "register_operand" "=S")
-        (plus:SI (match_operand:SI 4 "register_operand" "1") (match_dup 5)))
-   (set (mem:BLK (match_dup 3))
-       (mem:BLK (match_dup 4)))
-   (use (match_dup 5))]
-  "!TARGET_64BIT"
-  "rep{%;} movsb"
-  [(set_attr "type" "str")
-   (set_attr "prefix_rep" "1")
-   (set_attr "memory" "both")
-   (set_attr "mode" "SI")])
-
-(define_insn "*rep_movqi_rex64"
-  [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
-   (set (match_operand:DI 0 "register_operand" "=D")
-        (plus:DI (match_operand:DI 3 "register_operand" "0")
-                (match_operand:DI 5 "register_operand" "2")))
-   (set (match_operand:DI 1 "register_operand" "=S")
-        (plus:DI (match_operand:DI 4 "register_operand" "1") (match_dup 5)))
+  [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
+   (set (match_operand:P 0 "register_operand" "=D")
+        (plus:P (match_operand:P 3 "register_operand" "0")
+               (match_operand:P 5 "register_operand" "2")))
+   (set (match_operand:P 1 "register_operand" "=S")
+        (plus:P (match_operand:P 4 "register_operand" "1") (match_dup 5)))
    (set (mem:BLK (match_dup 3))
        (mem:BLK (match_dup 4)))
    (use (match_dup 5))]
-  "TARGET_64BIT"
+  ""
   "rep{%;} movsb"
   [(set_attr "type" "str")
    (set_attr "prefix_rep" "1")
    (set_attr "memory" "both")
-   (set_attr "mode" "SI")])
+   (set_attr "mode" "QI")])
 
-(define_expand "setmemsi"
+(define_expand "setmem<mode>"
    [(use (match_operand:BLK 0 "memory_operand" ""))
-    (use (match_operand:SI 1 "nonmemory_operand" ""))
+    (use (match_operand:SWI48 1 "nonmemory_operand" ""))
     (use (match_operand 2 "const_int_operand" ""))
     (use (match_operand 3 "const_int_operand" ""))
     (use (match_operand:SI 4 "const_int_operand" ""))
    FAIL;
 })
 
-(define_expand "setmemdi"
-   [(use (match_operand:BLK 0 "memory_operand" ""))
-    (use (match_operand:DI 1 "nonmemory_operand" ""))
-    (use (match_operand 2 "const_int_operand" ""))
-    (use (match_operand 3 "const_int_operand" ""))
-    (use (match_operand 4 "const_int_operand" ""))
-    (use (match_operand 5 "const_int_operand" ""))]
-  "TARGET_64BIT"
-{
- if (ix86_expand_setmem (operands[0], operands[1],
-                        operands[2], operands[3],
-                        operands[4], operands[5]))
-   DONE;
- else
-   FAIL;
-})
-
 ;; Most CPUs don't like single string operations
 ;; Handle this case here to simplify previous expander.
 
    (set_attr "mode" "DI")])
 
 (define_insn "*strsetsi_1"
-  [(set (mem:SI (match_operand:SI 1 "register_operand" "0"))
-       (match_operand:SI 2 "register_operand" "a"))
-   (set (match_operand:SI 0 "register_operand" "=D")
-       (plus:SI (match_dup 1)
-                (const_int 4)))]
-  "!TARGET_64BIT"
-  "stos{l|d}"
-  [(set_attr "type" "str")
-   (set_attr "memory" "store")
-   (set_attr "mode" "SI")])
-
-(define_insn "*strsetsi_rex_1"
-  [(set (mem:SI (match_operand:DI 1 "register_operand" "0"))
+  [(set (mem:SI (match_operand:P 1 "register_operand" "0"))
        (match_operand:SI 2 "register_operand" "a"))
-   (set (match_operand:DI 0 "register_operand" "=D")
-       (plus:DI (match_dup 1)
-                (const_int 4)))]
-  "TARGET_64BIT"
+   (set (match_operand:P 0 "register_operand" "=D")
+       (plus:P (match_dup 1)
+               (const_int 4)))]
+  ""
   "stos{l|d}"
   [(set_attr "type" "str")
    (set_attr "memory" "store")
    (set_attr "mode" "SI")])
 
 (define_insn "*strsethi_1"
-  [(set (mem:HI (match_operand:SI 1 "register_operand" "0"))
-       (match_operand:HI 2 "register_operand" "a"))
-   (set (match_operand:SI 0 "register_operand" "=D")
-       (plus:SI (match_dup 1)
-                (const_int 2)))]
-  "!TARGET_64BIT"
-  "stosw"
-  [(set_attr "type" "str")
-   (set_attr "memory" "store")
-   (set_attr "mode" "HI")])
-
-(define_insn "*strsethi_rex_1"
-  [(set (mem:HI (match_operand:DI 1 "register_operand" "0"))
+  [(set (mem:HI (match_operand:P 1 "register_operand" "0"))
        (match_operand:HI 2 "register_operand" "a"))
-   (set (match_operand:DI 0 "register_operand" "=D")
-       (plus:DI (match_dup 1)
-                (const_int 2)))]
-  "TARGET_64BIT"
+   (set (match_operand:P 0 "register_operand" "=D")
+       (plus:P (match_dup 1)
+               (const_int 2)))]
+  ""
   "stosw"
   [(set_attr "type" "str")
    (set_attr "memory" "store")
    (set_attr "mode" "HI")])
 
 (define_insn "*strsetqi_1"
-  [(set (mem:QI (match_operand:SI 1 "register_operand" "0"))
+  [(set (mem:QI (match_operand:P 1 "register_operand" "0"))
        (match_operand:QI 2 "register_operand" "a"))
-   (set (match_operand:SI 0 "register_operand" "=D")
-       (plus:SI (match_dup 1)
-                (const_int 1)))]
-  "!TARGET_64BIT"
+   (set (match_operand:P 0 "register_operand" "=D")
+       (plus:P (match_dup 1)
+               (const_int 1)))]
+  ""
   "stosb"
   [(set_attr "type" "str")
    (set_attr "memory" "store")
-   (set_attr "mode" "QI")])
-
-(define_insn "*strsetqi_rex_1"
-  [(set (mem:QI (match_operand:DI 1 "register_operand" "0"))
-       (match_operand:QI 2 "register_operand" "a"))
-   (set (match_operand:DI 0 "register_operand" "=D")
-       (plus:DI (match_dup 1)
-                (const_int 1)))]
-  "TARGET_64BIT"
-  "stosb"
-  [(set_attr "type" "str")
-   (set_attr "memory" "store")
-   (set_attr "prefix_rex" "0")
+   (set (attr "prefix_rex")
+       (if_then_else
+         (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
+         (const_string "0")
+         (const_string "*")))
    (set_attr "mode" "QI")])
 
 (define_expand "rep_stos"
    (set_attr "mode" "DI")])
 
 (define_insn "*rep_stossi"
-  [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
-   (set (match_operand:SI 0 "register_operand" "=D")
-        (plus:SI (ashift:SI (match_operand:SI 4 "register_operand" "1")
-                           (const_int 2))
-                (match_operand:SI 3 "register_operand" "0")))
+  [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
+   (set (match_operand:P 0 "register_operand" "=D")
+        (plus:P (ashift:P (match_operand:P 4 "register_operand" "1")
+                         (const_int 2))
+                (match_operand:P 3 "register_operand" "0")))
    (set (mem:BLK (match_dup 3))
        (const_int 0))
    (use (match_operand:SI 2 "register_operand" "a"))
    (use (match_dup 4))]
-  "!TARGET_64BIT"
-  "rep{%;} stos{l|d}"
-  [(set_attr "type" "str")
-   (set_attr "prefix_rep" "1")
-   (set_attr "memory" "store")
-   (set_attr "mode" "SI")])
-
-(define_insn "*rep_stossi_rex64"
-  [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
-   (set (match_operand:DI 0 "register_operand" "=D")
-        (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
-                           (const_int 2))
-                (match_operand:DI 3 "register_operand" "0")))
-   (set (mem:BLK (match_dup 3))
-       (const_int 0))
-   (use (match_operand:SI 2 "register_operand" "a"))
-   (use (match_dup 4))]
-  "TARGET_64BIT"
+  ""
   "rep{%;} stos{l|d}"
   [(set_attr "type" "str")
    (set_attr "prefix_rep" "1")
    (set_attr "mode" "SI")])
 
 (define_insn "*rep_stosqi"
-  [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
-   (set (match_operand:SI 0 "register_operand" "=D")
-        (plus:SI (match_operand:SI 3 "register_operand" "0")
-                (match_operand:SI 4 "register_operand" "1")))
+  [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
+   (set (match_operand:P 0 "register_operand" "=D")
+        (plus:P (match_operand:P 3 "register_operand" "0")
+               (match_operand:P 4 "register_operand" "1")))
    (set (mem:BLK (match_dup 3))
        (const_int 0))
    (use (match_operand:QI 2 "register_operand" "a"))
    (use (match_dup 4))]
-  "!TARGET_64BIT"
-  "rep{%;} stosb"
-  [(set_attr "type" "str")
-   (set_attr "prefix_rep" "1")
-   (set_attr "memory" "store")
-   (set_attr "mode" "QI")])
-
-(define_insn "*rep_stosqi_rex64"
-  [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
-   (set (match_operand:DI 0 "register_operand" "=D")
-        (plus:DI (match_operand:DI 3 "register_operand" "0")
-                (match_operand:DI 4 "register_operand" "1")))
-   (set (mem:BLK (match_dup 3))
-       (const_int 0))
-   (use (match_operand:QI 2 "register_operand" "a"))
-   (use (match_dup 4))]
-  "TARGET_64BIT"
+  ""
   "rep{%;} stosb"
   [(set_attr "type" "str")
    (set_attr "prefix_rep" "1")
    (set_attr "memory" "store")
-   (set_attr "prefix_rex" "0")
+   (set (attr "prefix_rex")
+       (if_then_else
+         (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
+         (const_string "0")
+         (const_string "*")))
    (set_attr "mode" "QI")])
 
 (define_expand "cmpstrnsi"
                             (match_dup 2)))
              (clobber (reg:CC FLAGS_REG))])]
   ""
-  "operands[1] = gen_reg_rtx (QImode);
-   operands[2] = gen_reg_rtx (QImode);")
+{
+  operands[1] = gen_reg_rtx (QImode);
+  operands[2] = gen_reg_rtx (QImode);
+})
 
 ;; memcmp recognizers.  The `cmpsb' opcode does nothing if the count is
 ;; zero.  Emit extra code to make sure that a zero-length compare is EQ.
 
 (define_insn "*cmpstrnqi_nz_1"
   [(set (reg:CC FLAGS_REG)
-       (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
-                   (mem:BLK (match_operand:SI 5 "register_operand" "1"))))
-   (use (match_operand:SI 6 "register_operand" "2"))
-   (use (match_operand:SI 3 "immediate_operand" "i"))
-   (clobber (match_operand:SI 0 "register_operand" "=S"))
-   (clobber (match_operand:SI 1 "register_operand" "=D"))
-   (clobber (match_operand:SI 2 "register_operand" "=c"))]
-  "!TARGET_64BIT"
-  "repz{%;} cmpsb"
-  [(set_attr "type" "str")
-   (set_attr "mode" "QI")
-   (set_attr "prefix_rep" "1")])
-
-(define_insn "*cmpstrnqi_nz_rex_1"
-  [(set (reg:CC FLAGS_REG)
-       (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
-                   (mem:BLK (match_operand:DI 5 "register_operand" "1"))))
-   (use (match_operand:DI 6 "register_operand" "2"))
+       (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
+                   (mem:BLK (match_operand:P 5 "register_operand" "1"))))
+   (use (match_operand:P 6 "register_operand" "2"))
    (use (match_operand:SI 3 "immediate_operand" "i"))
-   (clobber (match_operand:DI 0 "register_operand" "=S"))
-   (clobber (match_operand:DI 1 "register_operand" "=D"))
-   (clobber (match_operand:DI 2 "register_operand" "=c"))]
-  "TARGET_64BIT"
+   (clobber (match_operand:P 0 "register_operand" "=S"))
+   (clobber (match_operand:P 1 "register_operand" "=D"))
+   (clobber (match_operand:P 2 "register_operand" "=c"))]
+  ""
   "repz{%;} cmpsb"
   [(set_attr "type" "str")
    (set_attr "mode" "QI")
-   (set_attr "prefix_rex" "0")
+   (set (attr "prefix_rex")
+       (if_then_else
+         (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
+         (const_string "0")
+         (const_string "*")))
    (set_attr "prefix_rep" "1")])
 
 ;; The same, but the count is not known to not be zero.
 
 (define_insn "*cmpstrnqi_1"
   [(set (reg:CC FLAGS_REG)
-       (if_then_else:CC (ne (match_operand:SI 6 "register_operand" "2")
+       (if_then_else:CC (ne (match_operand:P 6 "register_operand" "2")
                             (const_int 0))
-         (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
-                     (mem:BLK (match_operand:SI 5 "register_operand" "1")))
+         (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
+                     (mem:BLK (match_operand:P 5 "register_operand" "1")))
          (const_int 0)))
    (use (match_operand:SI 3 "immediate_operand" "i"))
    (use (reg:CC FLAGS_REG))
-   (clobber (match_operand:SI 0 "register_operand" "=S"))
-   (clobber (match_operand:SI 1 "register_operand" "=D"))
-   (clobber (match_operand:SI 2 "register_operand" "=c"))]
-  "!TARGET_64BIT"
-  "repz{%;} cmpsb"
-  [(set_attr "type" "str")
-   (set_attr "mode" "QI")
-   (set_attr "prefix_rep" "1")])
-
-(define_insn "*cmpstrnqi_rex_1"
-  [(set (reg:CC FLAGS_REG)
-       (if_then_else:CC (ne (match_operand:DI 6 "register_operand" "2")
-                            (const_int 0))
-         (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
-                     (mem:BLK (match_operand:DI 5 "register_operand" "1")))
-         (const_int 0)))
-   (use (match_operand:SI 3 "immediate_operand" "i"))
-   (use (reg:CC FLAGS_REG))
-   (clobber (match_operand:DI 0 "register_operand" "=S"))
-   (clobber (match_operand:DI 1 "register_operand" "=D"))
-   (clobber (match_operand:DI 2 "register_operand" "=c"))]
-  "TARGET_64BIT"
+   (clobber (match_operand:P 0 "register_operand" "=S"))
+   (clobber (match_operand:P 1 "register_operand" "=D"))
+   (clobber (match_operand:P 2 "register_operand" "=c"))]
+  ""
   "repz{%;} cmpsb"
   [(set_attr "type" "str")
    (set_attr "mode" "QI")
-   (set_attr "prefix_rex" "0")
+   (set (attr "prefix_rex")
+       (if_then_else
+         (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
+         (const_string "0")
+         (const_string "*")))
    (set_attr "prefix_rep" "1")])
 
-(define_expand "strlensi"
-  [(set (match_operand:SI 0 "register_operand" "")
-       (unspec:SI [(match_operand:BLK 1 "general_operand" "")
-                   (match_operand:QI 2 "immediate_operand" "")
-                   (match_operand 3 "immediate_operand" "")] UNSPEC_SCAS))]
-  ""
-{
- if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
-   DONE;
- else
-   FAIL;
-})
-
-(define_expand "strlendi"
-  [(set (match_operand:DI 0 "register_operand" "")
-       (unspec:DI [(match_operand:BLK 1 "general_operand" "")
-                   (match_operand:QI 2 "immediate_operand" "")
-                   (match_operand 3 "immediate_operand" "")] UNSPEC_SCAS))]
+(define_expand "strlen<mode>"
+  [(set (match_operand:SWI48x 0 "register_operand" "")
+       (unspec:SWI48x [(match_operand:BLK 1 "general_operand" "")
+                       (match_operand:QI 2 "immediate_operand" "")
+                       (match_operand 3 "immediate_operand" "")]
+                      UNSPEC_SCAS))]
   ""
 {
  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
 })
 
 (define_expand "strlenqi_1"
-  [(parallel [(set (match_operand 0 "register_operand" "") (match_operand 2 "" ""))
+  [(parallel [(set (match_operand 0 "register_operand" "")
+                  (match_operand 2 "" ""))
              (clobber (match_operand 1 "register_operand" ""))
              (clobber (reg:CC FLAGS_REG))])]
   ""
   "ix86_current_function_needs_cld = 1;")
 
 (define_insn "*strlenqi_1"
-  [(set (match_operand:SI 0 "register_operand" "=&c")
-       (unspec:SI [(mem:BLK (match_operand:SI 5 "register_operand" "1"))
-                   (match_operand:QI 2 "register_operand" "a")
-                   (match_operand:SI 3 "immediate_operand" "i")
-                   (match_operand:SI 4 "register_operand" "0")] UNSPEC_SCAS))
-   (clobber (match_operand:SI 1 "register_operand" "=D"))
+  [(set (match_operand:P 0 "register_operand" "=&c")
+       (unspec:P [(mem:BLK (match_operand:P 5 "register_operand" "1"))
+                  (match_operand:QI 2 "register_operand" "a")
+                  (match_operand:P 3 "immediate_operand" "i")
+                  (match_operand:P 4 "register_operand" "0")] UNSPEC_SCAS))
+   (clobber (match_operand:P 1 "register_operand" "=D"))
    (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT"
-  "repnz{%;} scasb"
-  [(set_attr "type" "str")
-   (set_attr "mode" "QI")
-   (set_attr "prefix_rep" "1")])
-
-(define_insn "*strlenqi_rex_1"
-  [(set (match_operand:DI 0 "register_operand" "=&c")
-       (unspec:DI [(mem:BLK (match_operand:DI 5 "register_operand" "1"))
-                   (match_operand:QI 2 "register_operand" "a")
-                   (match_operand:DI 3 "immediate_operand" "i")
-                   (match_operand:DI 4 "register_operand" "0")] UNSPEC_SCAS))
-   (clobber (match_operand:DI 1 "register_operand" "=D"))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT"
+  ""
   "repnz{%;} scasb"
   [(set_attr "type" "str")
    (set_attr "mode" "QI")
-   (set_attr "prefix_rex" "0")
+   (set (attr "prefix_rex")
+       (if_then_else
+         (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
+         (const_string "0")
+         (const_string "*")))
    (set_attr "prefix_rep" "1")])
 
 ;; Peephole optimizations to clean up after cmpstrn*.  This should be
              (const_int 0)])
            (const_int -1)
            (const_int 0)))
-     (clobber (reg:CC FLAGS_REG))])]
-  ""
-  "")
+     (clobber (reg:CC FLAGS_REG))])])
 
 (define_insn "*x86_mov<mode>cc_0_m1"
   [(set (match_operand:SWI48 0 "register_operand" "=r")
    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
   "if (ix86_expand_fp_movcc (operands)) DONE; else FAIL;")
 
-(define_insn "*movsfcc_1_387"
-  [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
-       (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
+(define_insn "*movxfcc_1"
+  [(set (match_operand:XF 0 "register_operand" "=f,f")
+       (if_then_else:XF (match_operator 1 "fcmov_comparison_operator"
                                [(reg FLAGS_REG) (const_int 0)])
-                     (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
-                     (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
-  "TARGET_80387 && TARGET_CMOVE
+                     (match_operand:XF 2 "register_operand" "f,0")
+                     (match_operand:XF 3 "register_operand" "0,f")))]
+  "TARGET_80387 && TARGET_CMOVE"
+  "@
+   fcmov%F1\t{%2, %0|%0, %2}
+   fcmov%f1\t{%3, %0|%0, %3}"
+  [(set_attr "type" "fcmov")
+   (set_attr "mode" "XF")])
+
+(define_insn "*movdfcc_1_rex64"
+  [(set (match_operand:DF 0 "register_operand" "=f,f,r,r")
+       (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
+                               [(reg FLAGS_REG) (const_int 0)])
+                     (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
+                     (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
+  "TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
   "@
    fcmov%F1\t{%2, %0|%0, %2}
    cmov%O2%C1\t{%2, %0|%0, %2}
    cmov%O2%c1\t{%3, %0|%0, %3}"
   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
-   (set_attr "mode" "SF,SF,SI,SI")])
+   (set_attr "mode" "DF,DF,DI,DI")])
 
 (define_insn "*movdfcc_1"
   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r")
    #
    #"
   [(set_attr "type" "fcmov,fcmov,multi,multi")
-   (set_attr "mode" "DF")])
-
-(define_insn "*movdfcc_1_rex64"
-  [(set (match_operand:DF 0 "register_operand" "=f,f,r,r")
-       (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
-                               [(reg FLAGS_REG) (const_int 0)])
-                     (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
-                     (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
-  "TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
-   && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
-  "@
-   fcmov%F1\t{%2, %0|%0, %2}
-   fcmov%f1\t{%3, %0|%0, %3}
-   cmov%O2%C1\t{%2, %0|%0, %2}
-   cmov%O2%c1\t{%3, %0|%0, %3}"
-  [(set_attr "type" "fcmov,fcmov,icmov,icmov")
-   (set_attr "mode" "DF")])
+   (set_attr "mode" "DF,DF,DI,DI")])
 
 (define_split
   [(set (match_operand:DF 0 "register_and_not_any_fp_reg_operand" "")
                      (match_dup 7)
                      (match_dup 8)))]
 {
-  split_di (&operands[2], 2, &operands[5], &operands[7]);
-  split_di (&operands[0], 1, &operands[2], &operands[3]);
+  split_double_mode (DImode, &operands[2], 2, &operands[5], &operands[7]);
+  split_double_mode (DImode, &operands[0], 1, &operands[2], &operands[3]);
 })
 
-(define_insn "*movxfcc_1"
-  [(set (match_operand:XF 0 "register_operand" "=f,f")
-       (if_then_else:XF (match_operator 1 "fcmov_comparison_operator"
+(define_insn "*movsfcc_1_387"
+  [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
+       (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
                                [(reg FLAGS_REG) (const_int 0)])
-                     (match_operand:XF 2 "register_operand" "f,0")
-                     (match_operand:XF 3 "register_operand" "0,f")))]
-  "TARGET_80387 && TARGET_CMOVE"
+                     (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
+                     (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
+  "TARGET_80387 && TARGET_CMOVE
+   && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
   "@
    fcmov%F1\t{%2, %0|%0, %2}
-   fcmov%f1\t{%3, %0|%0, %3}"
-  [(set_attr "type" "fcmov")
-   (set_attr "mode" "XF")])
+   fcmov%f1\t{%3, %0|%0, %3}
+   cmov%O2%C1\t{%2, %0|%0, %2}
+   cmov%O2%c1\t{%3, %0|%0, %3}"
+  [(set_attr "type" "fcmov,fcmov,icmov,icmov")
+   (set_attr "mode" "SF,SF,SI,SI")])
 
 ;; All moves in XOP pcmov instructions are 128 bits and hence we restrict
 ;; the scalar versions to have only XMM registers as operands.
 ;;
 ;; in proper program order.
 
-(define_insn "pro_epilogue_adjust_stack_<mode>_1"
+(define_insn "pro_epilogue_adjust_stack_<mode>_add"
   [(set (match_operand:P 0 "register_operand" "=r,r")
        (plus:P (match_operand:P 1 "register_operand" "0,r")
-               (match_operand:P 2 "<immediate_operand>" "<i>,<i>")))
+               (match_operand:P 2 "<nonmemory_operand>" "r<i>,l<i>")))
    (clobber (reg:CC FLAGS_REG))
    (clobber (mem:BLK (scratch)))]
   ""
              (const_string "*")))
    (set_attr "mode" "<MODE>")])
 
-(define_insn "pro_epilogue_adjust_stack_di_2"
-  [(set (match_operand:DI 0 "register_operand" "=r,r")
-       (plus:DI (match_operand:DI 1 "register_operand" "0,r")
-                (match_operand:DI 3 "immediate_operand" "i,i")))
-   (use (match_operand:DI 2 "register_operand" "r,l"))
+(define_insn "pro_epilogue_adjust_stack_<mode>_sub"
+  [(set (match_operand:P 0 "register_operand" "=r")
+       (minus:P (match_operand:P 1 "register_operand" "0")
+                (match_operand:P 2 "register_operand" "r")))
    (clobber (reg:CC FLAGS_REG))
    (clobber (mem:BLK (scratch)))]
-  "TARGET_64BIT"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_ALU:
-      return "add{q}\t{%2, %0|%0, %2}";
-
-    case TYPE_LEA:
-      operands[2] = gen_rtx_PLUS (DImode, operands[1], operands[2]);
-      return "lea{q}\t{%a2, %0|%0, %a2}";
-
-    default:
-      gcc_unreachable ();
-    }
-}
-  [(set_attr "type" "alu,lea")
-   (set_attr "mode" "DI")])
-
-(define_insn "allocate_stack_worker_32"
-  [(set (match_operand:SI 0 "register_operand" "=a")
-       (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "0")]
-                           UNSPECV_STACK_PROBE))
-   (set (reg:SI SP_REG) (minus:SI (reg:SI SP_REG) (match_dup 1)))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT && ix86_target_stack_probe ()"
-  "call\t___chkstk"
-  [(set_attr "type" "multi")
-   (set_attr "length" "5")])
+  ""
+  "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
+  [(set_attr "type" "alu")
+   (set_attr "mode" "<MODE>")])
 
-(define_insn "allocate_stack_worker_64"
-  [(set (match_operand:DI 0 "register_operand" "=a")
-       (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "0")]
+(define_insn "allocate_stack_worker_probe_<mode>"
+  [(set (match_operand:P 0 "register_operand" "=a")
+       (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")]
                            UNSPECV_STACK_PROBE))
-   (set (reg:DI SP_REG) (minus:DI (reg:DI SP_REG) (match_dup 1)))
-   (clobber (reg:DI R10_REG))
-   (clobber (reg:DI R11_REG))
    (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && ix86_target_stack_probe ()"
-  "call\t___chkstk"
+  "ix86_target_stack_probe ()"
+  "call\t___chkstk_ms"
   [(set_attr "type" "multi")
    (set_attr "length" "5")])
 
     }
   else
     {
-      rtx (*gen_allocate_stack_worker) (rtx, rtx);
-
+      x = copy_to_mode_reg (Pmode, operands[1]);
       if (TARGET_64BIT)
-       gen_allocate_stack_worker = gen_allocate_stack_worker_64;
+        emit_insn (gen_allocate_stack_worker_probe_di (x, x));
       else
-       gen_allocate_stack_worker = gen_allocate_stack_worker_32;
-
-      x = copy_to_mode_reg (Pmode, operands[1]);
-      emit_insn (gen_allocate_stack_worker (x, x));
+        emit_insn (gen_allocate_stack_worker_probe_si (x, x));
+      x = expand_simple_binop (Pmode, MINUS, stack_pointer_rtx, x,
+                              stack_pointer_rtx, 0, OPTAB_DIRECT);
+      if (x != stack_pointer_rtx)
+       emit_move_insn (stack_pointer_rtx, x);
     }
 
   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
 ;; Call-value patterns last so that the wildcard operand does not
 ;; disrupt insn-recog's switch tables.
 
+(define_insn_and_split "*call_value_pop_0_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
+             (match_operand:SI 2 "" "")))
+   (set (reg:SI SP_REG)
+       (plus:SI (reg:SI SP_REG)
+                (match_operand:SI 3 "immediate_operand" "")))
+   (unspec [(match_operand 4 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_pop_vzeroupper (curr_insn, operands[4]); DONE;"
+  [(set_attr "type" "callv")])
+
 (define_insn "*call_value_pop_0"
   [(set (match_operand 0 "" "")
        (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
        (plus:SI (reg:SI SP_REG)
                 (match_operand:SI 3 "immediate_operand" "")))]
   "!TARGET_64BIT"
-{
-  if (SIBLING_CALL_P (insn))
-    return "jmp\t%P1";
-  else
-    return "call\t%P1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_pop_1_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lsm"))
+             (match_operand:SI 2 "" "")))
+   (set (reg:SI SP_REG)
+       (plus:SI (reg:SI SP_REG)
+                (match_operand:SI 3 "immediate_operand" "i")))
+   (unspec [(match_operand 4 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_pop_vzeroupper (curr_insn, operands[4]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_pop_1"
        (plus:SI (reg:SI SP_REG)
                 (match_operand:SI 3 "immediate_operand" "i")))]
   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
-{
-  if (constant_call_address_operand (operands[1], Pmode))
-    return "call\t%P1";
-  return "call\t%A1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*sibcall_value_pop_1_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
+             (match_operand:SI 2 "" "")))
+   (set (reg:SI SP_REG)
+       (plus:SI (reg:SI SP_REG)
+                (match_operand:SI 3 "immediate_operand" "i,i")))
+   (unspec [(match_operand 4 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_pop_vzeroupper (curr_insn, operands[4]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*sibcall_value_pop_1"
        (plus:SI (reg:SI SP_REG)
                 (match_operand:SI 3 "immediate_operand" "i,i")))]
   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
-  "@
-   jmp\t%P1
-   jmp\t%A1"
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_0_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
+             (match_operand:SI 2 "" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_0"
        (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
              (match_operand:SI 2 "" "")))]
   "!TARGET_64BIT"
-{
-  if (SIBLING_CALL_P (insn))
-    return "jmp\t%P1";
-  else
-    return "call\t%P1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_0_rex64_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
+             (match_operand:DI 2 "const_int_operand" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_0_rex64"
        (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
              (match_operand:DI 2 "const_int_operand" "")))]
   "TARGET_64BIT"
-{
-  if (SIBLING_CALL_P (insn))
-    return "jmp\t%P1";
-  else
-    return "call\t%P1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_0_rex64_ms_sysv_vzeroupper"
+  [(parallel
+    [(set (match_operand 0 "" "")
+         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
+               (match_operand:DI 2 "const_int_operand" "")))
+     (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
+     (clobber (reg:TI XMM6_REG))
+     (clobber (reg:TI XMM7_REG))
+     (clobber (reg:TI XMM8_REG))
+     (clobber (reg:TI XMM9_REG))
+     (clobber (reg:TI XMM10_REG))
+     (clobber (reg:TI XMM11_REG))
+     (clobber (reg:TI XMM12_REG))
+     (clobber (reg:TI XMM13_REG))
+     (clobber (reg:TI XMM14_REG))
+     (clobber (reg:TI XMM15_REG))
+     (clobber (reg:DI SI_REG))
+     (clobber (reg:DI DI_REG))])
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_0_rex64_ms_sysv"
    (clobber (reg:DI SI_REG))
    (clobber (reg:DI DI_REG))]
   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
-{
-  if (SIBLING_CALL_P (insn))
-    return "jmp\t%P1";
-  else
-    return "call\t%P1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_1_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lsm"))
+             (match_operand:SI 2 "" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_1"
        (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lsm"))
              (match_operand:SI 2 "" "")))]
   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
-{
-  if (constant_call_address_operand (operands[1], Pmode))
-    return "call\t%P1";
-  return "call\t%A1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*sibcall_value_1_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
+             (match_operand:SI 2 "" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*sibcall_value_1"
        (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
              (match_operand:SI 2 "" "")))]
   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
-  "@
-   jmp\t%P1
-   jmp\t%A1"
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_1_rex64_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
+             (match_operand:DI 2 "" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)
+   && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_1_rex64"
              (match_operand:DI 2 "" "")))]
   "TARGET_64BIT && !SIBLING_CALL_P (insn)
    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
-{
-  if (constant_call_address_operand (operands[1], Pmode))
-    return "call\t%P1";
-  return "call\t%A1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_1_rex64_ms_sysv_vzeroupper"
+  [(parallel
+    [(set (match_operand 0 "" "")
+         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
+               (match_operand:DI 2 "" "")))
+     (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
+     (clobber (reg:TI XMM6_REG))
+     (clobber (reg:TI XMM7_REG))
+     (clobber (reg:TI XMM8_REG))
+     (clobber (reg:TI XMM9_REG))
+     (clobber (reg:TI XMM10_REG))
+     (clobber (reg:TI XMM11_REG))
+     (clobber (reg:TI XMM12_REG))
+     (clobber (reg:TI XMM13_REG))
+     (clobber (reg:TI XMM14_REG))
+     (clobber (reg:TI XMM15_REG))
+     (clobber (reg:DI SI_REG))
+     (clobber (reg:DI DI_REG))])
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_1_rex64_ms_sysv"
    (clobber (reg:DI SI_REG))
    (clobber (reg:DI DI_REG))]
   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
-{
-  if (constant_call_address_operand (operands[1], Pmode))
-    return "call\t%P1";
-  return "call\t%A1";
-}
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*call_value_1_rex64_large_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rm"))
+             (match_operand:DI 2 "" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*call_value_1_rex64_large"
        (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rm"))
              (match_operand:DI 2 "" "")))]
   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
-  "call\t%A1"
+  { return ix86_output_call_insn (insn, operands[1], 1); }
+  [(set_attr "type" "callv")])
+
+(define_insn_and_split "*sibcall_value_1_rex64_vzeroupper"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:DI 1 "sibcall_insn_operand" "s,U"))
+             (match_operand:DI 2 "" "")))
+   (unspec [(match_operand 3 "const_int_operand" "")]
+          UNSPEC_CALL_NEEDS_VZEROUPPER)]
+  "TARGET_VZEROUPPER && TARGET_64BIT && SIBLING_CALL_P (insn)"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+  "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
   [(set_attr "type" "callv")])
 
 (define_insn "*sibcall_value_1_rex64"
        (call (mem:QI (match_operand:DI 1 "sibcall_insn_operand" "s,U"))
              (match_operand:DI 2 "" "")))]
   "TARGET_64BIT && SIBLING_CALL_P (insn)"
-  "@
-   jmp\t%P1
-   jmp\t%A1"
+  { return ix86_output_call_insn (insn, operands[1], 1); }
   [(set_attr "type" "callv")])
 \f
 ;; We used to use "int $5", in honor of #BR which maps to interrupt vector 5.
    (match_operand 1 "memory_operand" "")]
   ""
 {
+  rtx (*insn)(rtx, rtx);
+
 #ifdef TARGET_THREAD_SSP_OFFSET
-  if (TARGET_64BIT)
-    emit_insn (gen_stack_tls_protect_set_di (operands[0],
-                                       GEN_INT (TARGET_THREAD_SSP_OFFSET)));
-  else
-    emit_insn (gen_stack_tls_protect_set_si (operands[0],
-                                       GEN_INT (TARGET_THREAD_SSP_OFFSET)));
+  operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
+  insn = (TARGET_64BIT
+         ? gen_stack_tls_protect_set_di
+         : gen_stack_tls_protect_set_si);
 #else
-  if (TARGET_64BIT)
-    emit_insn (gen_stack_protect_set_di (operands[0], operands[1]));
-  else
-    emit_insn (gen_stack_protect_set_si (operands[0], operands[1]));
+  insn = (TARGET_64BIT
+         ? gen_stack_protect_set_di
+         : gen_stack_protect_set_si);
 #endif
+
+  emit_insn (insn (operands[0], operands[1]));
   DONE;
 })
 
-(define_insn "stack_protect_set_si"
-  [(set (match_operand:SI 0 "memory_operand" "=m")
-       (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
-   (set (match_scratch:SI 2 "=&r") (const_int 0))
+(define_insn "stack_protect_set_<mode>"
+  [(set (match_operand:P 0 "memory_operand" "=m")
+       (unspec:P [(match_operand:P 1 "memory_operand" "m")] UNSPEC_SP_SET))
+   (set (match_scratch:P 2 "=&r") (const_int 0))
    (clobber (reg:CC FLAGS_REG))]
   ""
-  "mov{l}\t{%1, %2|%2, %1}\;mov{l}\t{%2, %0|%0, %2}\;xor{l}\t%2, %2"
+  "mov{<imodesuffix>}\t{%1, %2|%2, %1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
   [(set_attr "type" "multi")])
 
-(define_insn "stack_protect_set_di"
-  [(set (match_operand:DI 0 "memory_operand" "=m")
-       (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
-   (set (match_scratch:DI 2 "=&r") (const_int 0))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT"
-  "mov{q}\t{%1, %2|%2, %1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
-  [(set_attr "type" "multi")])
-
-(define_insn "stack_tls_protect_set_si"
-  [(set (match_operand:SI 0 "memory_operand" "=m")
-       (unspec:SI [(match_operand:SI 1 "const_int_operand" "i")]
-                  UNSPEC_SP_TLS_SET))
-   (set (match_scratch:SI 2 "=&r") (const_int 0))
+(define_insn "stack_tls_protect_set_<mode>"
+  [(set (match_operand:P 0 "memory_operand" "=m")
+       (unspec:P [(match_operand:P 1 "const_int_operand" "i")]
+                 UNSPEC_SP_TLS_SET))
+   (set (match_scratch:P 2 "=&r") (const_int 0))
    (clobber (reg:CC FLAGS_REG))]
   ""
-  "mov{l}\t{%%gs:%P1, %2|%2, DWORD PTR gs:%P1}\;mov{l}\t{%2, %0|%0, %2}\;xor{l}\t%2, %2"
-  [(set_attr "type" "multi")])
-
-(define_insn "stack_tls_protect_set_di"
-  [(set (match_operand:DI 0 "memory_operand" "=m")
-       (unspec:DI [(match_operand:DI 1 "const_int_operand" "i")]
-                  UNSPEC_SP_TLS_SET))
-   (set (match_scratch:DI 2 "=&r") (const_int 0))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT"
-  {
-     /* The kernel uses a different segment register for performance reasons; a
-        system call would not have to trash the userspace segment register,
-        which would be expensive */
-     if (ix86_cmodel != CM_KERNEL)
-        return "mov{q}\t{%%fs:%P1, %2|%2, QWORD PTR fs:%P1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2";
-     else
-        return "mov{q}\t{%%gs:%P1, %2|%2, QWORD PTR gs:%P1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2";
-  }
+  "mov{<imodesuffix>}\t{%@:%P1, %2|%2, <iptrsize> PTR %@:%P1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
   [(set_attr "type" "multi")])
 
 (define_expand "stack_protect_test"
 {
   rtx flags = gen_rtx_REG (CCZmode, FLAGS_REG);
 
+  rtx (*insn)(rtx, rtx, rtx);
+
 #ifdef TARGET_THREAD_SSP_OFFSET
-  if (TARGET_64BIT)
-    emit_insn (gen_stack_tls_protect_test_di (flags, operands[0],
-                                       GEN_INT (TARGET_THREAD_SSP_OFFSET)));
-  else
-    emit_insn (gen_stack_tls_protect_test_si (flags, operands[0],
-                                       GEN_INT (TARGET_THREAD_SSP_OFFSET)));
+  operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
+  insn = (TARGET_64BIT
+         ? gen_stack_tls_protect_test_di
+         : gen_stack_tls_protect_test_si);
 #else
-  if (TARGET_64BIT)
-    emit_insn (gen_stack_protect_test_di (flags, operands[0], operands[1]));
-  else
-    emit_insn (gen_stack_protect_test_si (flags, operands[0], operands[1]));
+  insn = (TARGET_64BIT
+         ? gen_stack_protect_test_di
+         : gen_stack_protect_test_si);
 #endif
 
+  emit_insn (insn (flags, operands[0], operands[1]));
+
   emit_jump_insn (gen_cbranchcc4 (gen_rtx_EQ (VOIDmode, flags, const0_rtx),
                                  flags, const0_rtx, operands[2]));
   DONE;
 })
 
-(define_insn "stack_protect_test_si"
+(define_insn "stack_protect_test_<mode>"
   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
-       (unspec:CCZ [(match_operand:SI 1 "memory_operand" "m")
-                    (match_operand:SI 2 "memory_operand" "m")]
+       (unspec:CCZ [(match_operand:P 1 "memory_operand" "m")
+                    (match_operand:P 2 "memory_operand" "m")]
                    UNSPEC_SP_TEST))
-   (clobber (match_scratch:SI 3 "=&r"))]
+   (clobber (match_scratch:P 3 "=&r"))]
   ""
-  "mov{l}\t{%1, %3|%3, %1}\;xor{l}\t{%2, %3|%3, %2}"
+  "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
   [(set_attr "type" "multi")])
 
-(define_insn "stack_protect_test_di"
+(define_insn "stack_tls_protect_test_<mode>"
   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
-       (unspec:CCZ [(match_operand:DI 1 "memory_operand" "m")
-                    (match_operand:DI 2 "memory_operand" "m")]
-                   UNSPEC_SP_TEST))
-   (clobber (match_scratch:DI 3 "=&r"))]
-  "TARGET_64BIT"
-  "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%2, %3|%3, %2}"
-  [(set_attr "type" "multi")])
-
-(define_insn "stack_tls_protect_test_si"
-  [(set (match_operand:CCZ 0 "flags_reg_operand" "")
-       (unspec:CCZ [(match_operand:SI 1 "memory_operand" "m")
-                    (match_operand:SI 2 "const_int_operand" "i")]
+       (unspec:CCZ [(match_operand:P 1 "memory_operand" "m")
+                    (match_operand:P 2 "const_int_operand" "i")]
                    UNSPEC_SP_TLS_TEST))
-   (clobber (match_scratch:SI 3 "=r"))]
+   (clobber (match_scratch:P 3 "=r"))]
   ""
-  "mov{l}\t{%1, %3|%3, %1}\;xor{l}\t{%%gs:%P2, %3|%3, DWORD PTR gs:%P2}"
-  [(set_attr "type" "multi")])
-
-(define_insn "stack_tls_protect_test_di"
-  [(set (match_operand:CCZ 0 "flags_reg_operand" "")
-       (unspec:CCZ [(match_operand:DI 1 "memory_operand" "m")
-                    (match_operand:DI 2 "const_int_operand" "i")]
-                   UNSPEC_SP_TLS_TEST))
-   (clobber (match_scratch:DI 3 "=r"))]
-  "TARGET_64BIT"
-  {
-     /* The kernel uses a different segment register for performance reasons; a
-        system call would not have to trash the userspace segment register,
-        which would be expensive */
-     if (ix86_cmodel != CM_KERNEL)
-        return "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%%fs:%P2, %3|%3, QWORD PTR fs:%P2}";
-     else
-        return "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%%gs:%P2, %3|%3, QWORD PTR gs:%P2}";
-  }
+  "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%@:%P2, %3|%3, <iptrsize> PTR %@:%P2}"
   [(set_attr "type" "multi")])
 
 (define_insn "sse4_2_crc32<mode>"
 (define_expand "lwp_llwpcb"
   [(unspec_volatile [(match_operand 0 "register_operand" "r")]
                    UNSPECV_LLWP_INTRINSIC)]
-  "TARGET_LWP"
-  "")
+  "TARGET_LWP")
 
 (define_insn "*lwp_llwpcb<mode>1"
   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
   [(set (match_operand 0 "register_operand" "=r")
        (unspec_volatile [(const_int 0)] UNSPECV_SLWP_INTRINSIC))]
   "TARGET_LWP"
-  {
-    if (TARGET_64BIT)
-      emit_insn (gen_lwp_slwpcbdi (operands[0]));
-    else
-      emit_insn (gen_lwp_slwpcbsi (operands[0]));
-    DONE;
-  })
+{
+  if (TARGET_64BIT)
+    emit_insn (gen_lwp_slwpcbdi (operands[0]));
+  else
+    emit_insn (gen_lwp_slwpcbsi (operands[0]));
+  DONE;
+})
 
 (define_insn "lwp_slwpcb<mode>"
   [(set (match_operand:P 0 "register_operand" "=r")
                             UNSPECV_LWPINS_INTRINSIC))
    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
        (eq:QI (reg:CCC FLAGS_REG) (const_int 0)))]
-  "TARGET_LWP"
-  "")
+  "TARGET_LWP")
 
 (define_insn "*lwp_lwpins<mode>3_1"
   [(set (reg:CCC FLAGS_REG)