OSDN Git Service

* config/i386/i386.md (ashr<mode>3): Macroize expander from
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.md
index 924433f..95220d3 100644 (file)
@@ -1,6 +1,6 @@
 ;; GCC machine description for IA-32 and x86-64.
 ;; Copyright (C) 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
 ;; Free Software Foundation, Inc.
 ;; Mostly by William Schelter.
 ;; x86_64 support added by Jan Hubicka
@@ -30,7 +30,6 @@
 ;; L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
 ;; C -- print opcode suffix for set/cmov insn.
 ;; c -- like C, but print reversed condition
-;; E,e -- likewise, but for compare-and-branch fused insn.
 ;; F,f -- likewise, but for floating-point.
 ;; O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
 ;;      otherwise nothing
 (define_mode_iterator SWIM248 [(HI "TARGET_HIMODE_MATH")
                               SI (DI "TARGET_64BIT")])
 
-;; Half mode for double word integer modes.
-(define_mode_iterator DWIH [(SI "!TARGET_64BIT")
-                           (DI "TARGET_64BIT")])
-
 ;; Double word integer modes.
+(define_mode_iterator DWI [(DI "!TARGET_64BIT")
+                          (TI "TARGET_64BIT")])
+
+;; Double word integer modes as mode attribute.
 (define_mode_attr DWI [(SI "DI") (DI "TI")])
 (define_mode_attr dwi [(SI "di") (DI "ti")])
 
+;; Half mode for double word integer modes.
+(define_mode_iterator DWIH [(SI "!TARGET_64BIT")
+                           (DI "TARGET_64BIT")])
+
 ;; Instruction suffix for integer modes.
 (define_mode_attr imodesuffix [(QI "b") (HI "w") (SI "l") (DI "q")])
 
 ;; Immediate operand constraint for double integer modes.
 (define_mode_attr di [(SI "iF") (DI "e")])
 
+;; Immediate operand constraint for shifts.
+(define_mode_attr S [(QI "I") (HI "I") (SI "I") (DI "J") (TI "O")])
+
 ;; General operand predicate for integer modes.
 (define_mode_attr general_operand
        [(QI "general_operand")
         (SI "general_operand")
         (DI "x86_64_szext_general_operand")])
 
+;; Operand predicate for shifts.
+(define_mode_attr shift_operand
+       [(QI "nonimmediate_operand")
+        (HI "nonimmediate_operand")
+        (SI "nonimmediate_operand")
+        (DI "shiftdi_operand")
+        (TI "register_operand")])
+
+;; Operand predicate for shift argument.
+(define_mode_attr shift_immediate_operand
+       [(QI "const_1_to_31_operand")
+        (HI "const_1_to_31_operand")
+        (SI "const_1_to_31_operand")
+        (DI "const_1_to_63_operand")])
+
+;; Input operand predicate for arithmetic left shifts.
+(define_mode_attr ashl_input_operand
+       [(QI "nonimmediate_operand")
+        (HI "nonimmediate_operand")
+        (SI "nonimmediate_operand")
+        (DI "ashldi_input_operand")
+        (TI "reg_or_pm1_operand")])
+
 ;; SSE and x87 SFmode and DFmode floating point modes
 (define_mode_iterator MODEF [SF DF])
 
       && true_regnum (operands[1]) == AX_REG
       && true_regnum (operands[2]) == DX_REG)
     {
-      emit_insn (gen_ashrsi3_31 (operands[2], operands[1], GEN_INT (31)));
+      emit_insn (gen_ashrsi3_cvt (operands[2], operands[1], GEN_INT (31)));
     }
   else
     {
       emit_move_insn (operands[2], operands[1]);
-      emit_insn (gen_ashrsi3_31 (operands[2], operands[2], GEN_INT (31)));
+      emit_insn (gen_ashrsi3_cvt (operands[2], operands[2], GEN_INT (31)));
     }
   emit_move_insn (operands[4], operands[2]);
   DONE;
   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
       && true_regnum (operands[3]) == AX_REG)
     {
-      emit_insn (gen_ashrsi3_31 (operands[4], operands[3], GEN_INT (31)));
+      emit_insn (gen_ashrsi3_cvt (operands[4], operands[3], GEN_INT (31)));
       DONE;
     }
 
   if (true_regnum (operands[4]) != true_regnum (operands[1]))
     emit_move_insn (operands[4], operands[1]);
 
-  emit_insn (gen_ashrsi3_31 (operands[4], operands[4], GEN_INT (31)));
+  emit_insn (gen_ashrsi3_cvt (operands[4], operands[4], GEN_INT (31)));
   DONE;
 })
 
         return "add{<imodesuffix>}\t{%1, %0|%0, %1}";
         
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
 
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{l}\t{%2, %k0|%k0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+        return "sub{l}\t{%2, %k0|%k0, %2}";
+
       return "add{l}\t{%2, %k0|%k0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
        {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
          if (widen)
            return "sub{l}\t{%2, %k0|%k0, %2}";
          else
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
        {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
          if (widen)
            return "sub{l}\t{%2, %k0|%k0, %2}";
          else
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[1])
-         && INTVAL (operands[1]) < 0)
-       {
-         operands[1] = GEN_INT (-INTVAL (operands[1]));
-         return "sub{b}\t{%1, %0|%0, %1}";
-       }
+      if (x86_maybe_negate_const_int (&operands[1], QImode))
+       return "sub{b}\t{%1, %0|%0, %1}";
+
       return "add{b}\t{%1, %0|%0, %1}";
     }
 }
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
       /* ???? In DImode, we ought to handle there the 32bit case too
         - do we need new constraint?  */
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
+
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{l}\t{%2, %k0|%k0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+        return "sub{l}\t{%2, %k0|%k0, %2}";
+
       return "add{l}\t{%2, %k0|%k0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[2])
-          && INTVAL (operands[2]) < 0)
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{b}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "sub{b}\t{%2, %0|%0, %2}";
+
       return "add{b}\t{%2, %0|%0, %2}";
     }
 }
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
       /* ???? In DImode, we ought to handle there the 32bit case too
         - do we need new constraint?  */
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
+
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{l}\t{%2, %k0|%k0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+        return "sub{l}\t{%2, %k0|%k0, %2}";
+
       return "add{l}\t{%2, %k0|%k0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[2])
-          && INTVAL (operands[2]) < 0)
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{b}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "sub{b}\t{%2, %0|%0, %2}";
+
       return "add{b}\t{%2, %0|%0, %2}";
     }
 }
 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
 ; is matched then.  We can't accept general immediate, because for
 ; case of overflows,  the result is messed up.
-; This pattern also don't hold of 0x8000000000000000, since the value
-; overflows when negated.
 ; Also carry flag is reversed compared to cmp, so this conversion is valid
 ; only for comparisons not depending on it.
 
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if ((INTVAL (operands[2]) == -128
-          || (INTVAL (operands[2]) > 0
-              && INTVAL (operands[2]) != 128))
-         /* Avoid overflows.  */
-         && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-       return "sub{q}\t{%2, %0|%0, %2}";
-      operands[2] = GEN_INT (-INTVAL (operands[2]));
-      return "add{q}\t{%2, %0|%0, %2}";
+      if (x86_maybe_negate_const_int (&operands[2], DImode))
+       return "add{q}\t{%2, %0|%0, %2}";
+
+      return "sub{q}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
 ; is matched then.  We can't accept general immediate, because for
 ; case of overflows,  the result is messed up.
-; This pattern also don't hold of 0x80000000, since the value overflows
-; when negated.
 ; Also carry flag is reversed compared to cmp, so this conversion is valid
 ; only for comparisons not depending on it.
 
          (match_operand:SI 1 "nonimmediate_operand" "0")
          (match_operand:SI 2 "const_int_operand" "n")))
    (clobber (match_scratch:SI 0 "=rm"))]
-  "ix86_match_ccmode (insn, CCGCmode)
-   && (INTVAL (operands[2]) & 0xffffffff) != 0x80000000"
+  "ix86_match_ccmode (insn, CCGCmode)"
 {
   switch (get_attr_type (insn))
     {
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if ((INTVAL (operands[2]) == -128
-          || (INTVAL (operands[2]) > 0
-              && INTVAL (operands[2]) != 128)))
-       return "sub{l}\t{%2, %0|%0, %2}";
-      operands[2] = GEN_INT (-INTVAL (operands[2]));
-      return "add{l}\t{%2, %0|%0, %2}";
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+       return "add{l}\t{%2, %0|%0, %2}";
+
+      return "sub{l}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
          (match_operand:HI 1 "nonimmediate_operand" "0")
          (match_operand:HI 2 "const_int_operand" "n")))
    (clobber (match_scratch:HI 0 "=rm"))]
-  "ix86_match_ccmode (insn, CCGCmode)
-   && (INTVAL (operands[2]) & 0xffff) != 0x8000"
+  "ix86_match_ccmode (insn, CCGCmode)"
 {
   switch (get_attr_type (insn))
     {
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if ((INTVAL (operands[2]) == -128
-          || (INTVAL (operands[2]) > 0
-              && INTVAL (operands[2]) != 128)))
-       return "sub{w}\t{%2, %0|%0, %2}";
-      operands[2] = GEN_INT (-INTVAL (operands[2]));
-      return "add{w}\t{%2, %0|%0, %2}";
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "add{w}\t{%2, %0|%0, %2}";
+
+      return "sub{w}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
          (match_operand:QI 1 "nonimmediate_operand" "0")
          (match_operand:QI 2 "const_int_operand" "n")))
    (clobber (match_scratch:QI 0 "=qm"))]
-  "ix86_match_ccmode (insn, CCGCmode)
-   && (INTVAL (operands[2]) & 0xff) != 0x80"
+  "ix86_match_ccmode (insn, CCGCmode)"
 {
   switch (get_attr_type (insn))
     {
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      if (INTVAL (operands[2]) < 0)
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "add{b}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "add{b}\t{%2, %0|%0, %2}";
+
       return "sub{b}\t{%2, %0|%0, %2}";
     }
 }
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
+
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[2])
-          && INTVAL (operands[2]) < 0)
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{b}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "sub{b}\t{%2, %0|%0, %2}";
+
       return "add{b}\t{%2, %0|%0, %2}";
     }
 }
 ;; shift pair, instead using moves and sign extension for counts greater
 ;; than 31.
 
-(define_expand "ashlti3"
-  [(set (match_operand:TI 0 "register_operand" "")
-       (ashift:TI (match_operand:TI 1 "reg_or_pm1_operand" "")
-                  (match_operand:QI 2 "nonmemory_operand" "")))]
-  "TARGET_64BIT"
-  "ix86_expand_binary_operator (ASHIFT, TImode, operands); DONE;")
+(define_expand "ashl<mode>3"
+  [(set (match_operand:SDWIM 0 "<shift_operand>" "")
+       (ashift:SDWIM (match_operand:SDWIM 1 "<ashl_input_operand>" "")
+                     (match_operand:QI 2 "nonmemory_operand" "")))]
+  ""
+  "ix86_expand_binary_operator (ASHIFT, <MODE>mode, operands); DONE;")
 
-(define_insn "*ashlti3_1"
-  [(set (match_operand:TI 0 "register_operand" "=&r,r")
-       (ashift:TI (match_operand:TI 1 "reg_or_pm1_operand" "n,0")
-                  (match_operand:QI 2 "nonmemory_operand" "Oc,Oc")))
+(define_insn "*ashl<mode>3_doubleword"
+  [(set (match_operand:DWI 0 "register_operand" "=&r,r")
+       (ashift:DWI (match_operand:DWI 1 "reg_or_pm1_operand" "n,0")
+                   (match_operand:QI 2 "nonmemory_operand" "<S>c,<S>c")))
    (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT"
+  ""
   "#"
   [(set_attr "type" "multi")])
 
+(define_split
+  [(set (match_operand:DWI 0 "register_operand" "")
+       (ashift:DWI (match_operand:DWI 1 "nonmemory_operand" "")
+                   (match_operand:QI 2 "nonmemory_operand" "")))
+   (clobber (reg:CC FLAGS_REG))]
+  "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
+  [(const_int 0)]
+  "ix86_split_ashl (operands, NULL_RTX, <MODE>mode); DONE;")
+
+;; By default we don't ask for a scratch register, because when DWImode
+;; values are manipulated, registers are already at a premium.  But if
+;; we have one handy, we won't turn it away.
+
 (define_peephole2
-  [(match_scratch:DI 3 "r")
-   (parallel [(set (match_operand:TI 0 "register_operand" "")
-                  (ashift:TI (match_operand:TI 1 "nonmemory_operand" "")
-                             (match_operand:QI 2 "nonmemory_operand" "")))
+  [(match_scratch:DWIH 3 "r")
+   (parallel [(set (match_operand:<DWI> 0 "register_operand" "")
+                  (ashift:<DWI>
+                    (match_operand:<DWI> 1 "nonmemory_operand" "")
+                    (match_operand:QI 2 "nonmemory_operand" "")))
              (clobber (reg:CC FLAGS_REG))])
    (match_dup 3)]
-  "TARGET_64BIT"
-  [(const_int 0)]
-  "ix86_split_ashl (operands, operands[3], TImode); DONE;")
-
-(define_split
-  [(set (match_operand:TI 0 "register_operand" "")
-       (ashift:TI (match_operand:TI 1 "nonmemory_operand" "")
-                  (match_operand:QI 2 "nonmemory_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
-                   ? epilogue_completed : reload_completed)"
+  "TARGET_CMOVE"
   [(const_int 0)]
-  "ix86_split_ashl (operands, NULL_RTX, TImode); DONE;")
+  "ix86_split_ashl (operands, operands[3], <DWI>mode); DONE;")
 
 (define_insn "x86_64_shld"
   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
    (set_attr "athlon_decode" "vector")
    (set_attr "amdfam10_decode" "vector")])
 
-(define_expand "x86_64_shift_adj_1"
+(define_insn "x86_shld"
+  [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
+        (ior:SI (ashift:SI (match_dup 0)
+                 (match_operand:QI 2 "nonmemory_operand" "Ic"))
+               (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
+                 (minus:QI (const_int 32) (match_dup 2)))))
+   (clobber (reg:CC FLAGS_REG))]
+  ""
+  "shld{l}\t{%s2%1, %0|%0, %1, %2}"
+  [(set_attr "type" "ishift")
+   (set_attr "prefix_0f" "1")
+   (set_attr "mode" "SI")
+   (set_attr "pent_pair" "np")
+   (set_attr "athlon_decode" "vector")
+   (set_attr "amdfam10_decode" "vector")])
+
+(define_expand "x86_shift<mode>_adj_1"
   [(set (reg:CCZ FLAGS_REG)
        (compare:CCZ (and:QI (match_operand:QI 2 "register_operand" "")
-                            (const_int 64))
+                            (match_dup 4))
                     (const_int 0)))
-   (set (match_operand:DI 0 "register_operand" "")
-        (if_then_else:DI (ne (reg:CCZ FLAGS_REG) (const_int 0))
-                        (match_operand:DI 1 "register_operand" "")
-                        (match_dup 0)))
+   (set (match_operand:SWI48 0 "register_operand" "")
+        (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
+                           (match_operand:SWI48 1 "register_operand" "")
+                           (match_dup 0)))
    (set (match_dup 1)
-       (if_then_else:DI (ne (reg:CCZ FLAGS_REG) (const_int 0))
-                        (match_operand:DI 3 "register_operand" "r")
-                        (match_dup 1)))]
-  "TARGET_64BIT"
-  "")
+       (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
+                           (match_operand:SWI48 3 "register_operand" "r")
+                           (match_dup 1)))]
+  "TARGET_CMOVE"
+  "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
 
-(define_expand "x86_64_shift_adj_2"
-  [(use (match_operand:DI 0 "register_operand" ""))
-   (use (match_operand:DI 1 "register_operand" ""))
+(define_expand "x86_shift<mode>_adj_2"
+  [(use (match_operand:SWI48 0 "register_operand" ""))
+   (use (match_operand:SWI48 1 "register_operand" ""))
    (use (match_operand:QI 2 "register_operand" ""))]
-  "TARGET_64BIT"
+  ""
 {
   rtx label = gen_label_rtx ();
   rtx tmp;
 
-  emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (64)));
+  emit_insn (gen_testqi_ccz_1 (operands[2],
+                              GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
 
   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
   DONE;
 })
 
-(define_expand "ashldi3"
-  [(set (match_operand:DI 0 "shiftdi_operand" "")
-       (ashift:DI (match_operand:DI 1 "ashldi_input_operand" "")
-                  (match_operand:QI 2 "nonmemory_operand" "")))]
-  ""
-  "ix86_expand_binary_operator (ASHIFT, DImode, operands); DONE;")
-
-(define_insn "*ashldi3_1_rex64"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
-       (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0,l")
-                  (match_operand:QI 2 "nonmemory_operand" "cJ,M")))
+(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")
+                     (match_operand:QI 2 "nonmemory_operand" "c<S>,M")))
    (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
+  "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
 {
   switch (get_attr_type (insn))
     {
     case TYPE_ALU:
       gcc_assert (operands[2] == const1_rtx);
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      return "add{q}\t%0, %0";
+      return "add{<imodesuffix>}\t%0, %0";
 
     case TYPE_LEA:
-      gcc_assert (CONST_INT_P (operands[2]));
-      gcc_assert ((unsigned HOST_WIDE_INT) INTVAL (operands[2]) <= 3);
-      operands[1] = gen_rtx_MULT (DImode, operands[1],
-                                 GEN_INT (1 << INTVAL (operands[2])));
-      return "lea{q}\t{%a1, %0|%0, %a1}";
+      return "#";
 
     default:
       if (REG_P (operands[2]))
-       return "sal{q}\t{%b2, %0|%0, %b2}";
+       return "sal{<imodesuffix>}\t{%b2, %0|%0, %b2}";
       else if (operands[2] == const1_rtx
               && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{q}\t%0";
+       return "sal{<imodesuffix>}\t%0";
       else
-       return "sal{q}\t{%2, %0|%0, %2}";
+       return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "DI")])
+   (set_attr "mode" "<MODE>")])
 
-;; Convert lea to the lea pattern to avoid flags dependency.
-(define_split
-  [(set (match_operand:DI 0 "register_operand" "")
-       (ashift:DI (match_operand:DI 1 "index_register_operand" "")
-                  (match_operand:QI 2 "immediate_operand" "")))
+(define_insn "*ashlsi3_1_zext"
+  [(set (match_operand:DI 0 "register_operand" "=r,r")
+       (zero_extend:DI
+         (ashift:SI (match_operand:SI 1 "register_operand" "0,l")
+                    (match_operand:QI 2 "nonmemory_operand" "cI,M"))))
    (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && reload_completed
-   && true_regnum (operands[0]) != true_regnum (operands[1])"
-  [(set (match_dup 0)
-       (mult:DI (match_dup 1)
-                (match_dup 2)))]
-  "operands[2] = gen_int_mode (1 << INTVAL (operands[2]), DImode);")
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashldi3_cmp_rex64"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_63_operand" "J"))
-         (const_int 0)))
-   (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
-       (ashift:DI (match_dup 1) (match_dup 2)))]
-  "TARGET_64BIT
-   && (optimize_function_for_size_p (cfun)
-       || !TARGET_PARTIAL_FLAG_REG_STALL
-       || (operands[2] == const1_rtx
-          && (TARGET_SHIFT1
-              || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
+  "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
 {
   switch (get_attr_type (insn))
     {
     case TYPE_ALU:
       gcc_assert (operands[2] == const1_rtx);
-      return "add{q}\t%0, %0";
+      return "add{l}\t%k0, %k0";
+
+    case TYPE_LEA:
+      return "#";
 
     default:
       if (REG_P (operands[2]))
-       return "sal{q}\t{%b2, %0|%0, %b2}";
+       return "sal{l}\t{%b2, %k0|%k0, %b2}";
       else if (operands[2] == const1_rtx
               && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{q}\t%0";
+       return "sal{l}\t%k0";
       else
-       return "sal{q}\t{%2, %0|%0, %2}";
+       return "sal{l}\t{%2, %k0|%k0, %2}";
     }
 }
   [(set (attr "type")
-     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
+     (cond [(eq_attr "alternative" "1")
+             (const_string "lea")
+            (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
+                    (const_int 0))
                 (match_operand 2 "const1_operand" ""))
              (const_string "alu")
           ]
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "DI")])
+   (set_attr "mode" "SI")])
 
-(define_insn "*ashldi3_cconly_rex64"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_63_operand" "J"))
-         (const_int 0)))
-   (clobber (match_scratch:DI 0 "=r"))]
-  "TARGET_64BIT
-   && (optimize_function_for_size_p (cfun)
-       || !TARGET_PARTIAL_FLAG_REG_STALL
-       || (operands[2] == const1_rtx
-          && (TARGET_SHIFT1
-              || TARGET_DOUBLE_WITH_ADD)))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
+(define_insn "*ashlhi3_1"
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
+       (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
+                  (match_operand:QI 2 "nonmemory_operand" "cI")))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_PARTIAL_REG_STALL
+   && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
 {
   switch (get_attr_type (insn))
     {
     case TYPE_ALU:
       gcc_assert (operands[2] == const1_rtx);
-      return "add{q}\t%0, %0";
+      return "add{w}\t%0, %0";
 
     default:
       if (REG_P (operands[2]))
-       return "sal{q}\t{%b2, %0|%0, %b2}";
+       return "sal{w}\t{%b2, %0|%0, %b2}";
       else if (operands[2] == const1_rtx
               && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{q}\t%0";
+       return "sal{w}\t%0";
       else
-       return "sal{q}\t{%2, %0|%0, %2}";
+       return "sal{w}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "DI")])
-
-(define_insn "*ashldi3_1"
-  [(set (match_operand:DI 0 "register_operand" "=&r,r")
-       (ashift:DI (match_operand:DI 1 "reg_or_pm1_operand" "n,0")
-                  (match_operand:QI 2 "nonmemory_operand" "Jc,Jc")))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT"
-  "#"
-  [(set_attr "type" "multi")])
-
-;; By default we don't ask for a scratch register, because when DImode
-;; values are manipulated, registers are already at a premium.  But if
-;; we have one handy, we won't turn it away.
-(define_peephole2
-  [(match_scratch:SI 3 "r")
-   (parallel [(set (match_operand:DI 0 "register_operand" "")
-                  (ashift:DI (match_operand:DI 1 "nonmemory_operand" "")
-                             (match_operand:QI 2 "nonmemory_operand" "")))
-             (clobber (reg:CC FLAGS_REG))])
-   (match_dup 3)]
-  "!TARGET_64BIT && TARGET_CMOVE"
-  [(const_int 0)]
-  "ix86_split_ashl (operands, operands[3], DImode); DONE;")
-
-(define_split
-  [(set (match_operand:DI 0 "register_operand" "")
-       (ashift:DI (match_operand:DI 1 "nonmemory_operand" "")
-                  (match_operand:QI 2 "nonmemory_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT && ((optimize > 0 && flag_peephole2)
-                    ? epilogue_completed : reload_completed)"
-  [(const_int 0)]
-  "ix86_split_ashl (operands, NULL_RTX, DImode); DONE;")
-
-(define_insn "x86_shld"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
-        (ior:SI (ashift:SI (match_dup 0)
-                 (match_operand:QI 2 "nonmemory_operand" "Ic"))
-               (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
-                 (minus:QI (const_int 32) (match_dup 2)))))
-   (clobber (reg:CC FLAGS_REG))]
-  ""
-  "shld{l}\t{%s2%1, %0|%0, %1, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "prefix_0f" "1")
-   (set_attr "mode" "SI")
-   (set_attr "pent_pair" "np")
-   (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "vector")])
-
-(define_expand "x86_shift_adj_1"
-  [(set (reg:CCZ FLAGS_REG)
-       (compare:CCZ (and:QI (match_operand:QI 2 "register_operand" "")
-                            (const_int 32))
-                    (const_int 0)))
-   (set (match_operand:SI 0 "register_operand" "")
-        (if_then_else:SI (ne (reg:CCZ FLAGS_REG) (const_int 0))
-                        (match_operand:SI 1 "register_operand" "")
-                        (match_dup 0)))
-   (set (match_dup 1)
-       (if_then_else:SI (ne (reg:CCZ FLAGS_REG) (const_int 0))
-                        (match_operand:SI 3 "register_operand" "r")
-                        (match_dup 1)))]
-  "TARGET_CMOVE"
-  "")
-
-(define_expand "x86_shift_adj_2"
-  [(use (match_operand:SI 0 "register_operand" ""))
-   (use (match_operand:SI 1 "register_operand" ""))
-   (use (match_operand:QI 2 "register_operand" ""))]
-  ""
-{
-  rtx label = gen_label_rtx ();
-  rtx tmp;
-
-  emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
-
-  tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
-  tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
-  tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
-                             gen_rtx_LABEL_REF (VOIDmode, label),
-                             pc_rtx);
-  tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
-  JUMP_LABEL (tmp) = label;
-
-  emit_move_insn (operands[0], operands[1]);
-  ix86_expand_clear (operands[1]);
-
-  emit_label (label);
-  LABEL_NUSES (label) = 1;
-
-  DONE;
-})
-
-(define_expand "ashlsi3"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "")
-       (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "")
-                  (match_operand:QI 2 "nonmemory_operand" "")))]
-  ""
-  "ix86_expand_binary_operator (ASHIFT, SImode, operands); DONE;")
+   (set_attr "mode" "HI")])
 
-(define_insn "*ashlsi3_1"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
-       (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0,l")
+(define_insn "*ashlhi3_1_lea"
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
+       (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,l")
                   (match_operand:QI 2 "nonmemory_operand" "cI,M")))
    (clobber (reg:CC FLAGS_REG))]
-  "ix86_binary_operator_ok (ASHIFT, SImode, operands)"
+  "!TARGET_PARTIAL_REG_STALL
+   && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
 {
   switch (get_attr_type (insn))
     {
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      return "add{l}\t%0, %0";
-
     case TYPE_LEA:
       return "#";
+    case TYPE_ALU:
+      gcc_assert (operands[2] == const1_rtx);
+      return "add{w}\t%0, %0";
 
     default:
       if (REG_P (operands[2]))
-       return "sal{l}\t{%b2, %0|%0, %b2}";
+       return "sal{w}\t{%b2, %0|%0, %b2}";
       else if (operands[2] == const1_rtx
               && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{l}\t%0";
+       return "sal{w}\t%0";
       else
-       return "sal{l}\t{%2, %0|%0, %2}";
+       return "sal{w}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "SI")])
-
-;; Convert lea to the lea pattern to avoid flags dependency.
-(define_split
-  [(set (match_operand 0 "register_operand" "")
-       (ashift (match_operand 1 "index_register_operand" "")
-                (match_operand:QI 2 "const_int_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "reload_completed
-   && true_regnum (operands[0]) != true_regnum (operands[1])
-   && GET_MODE_SIZE (GET_MODE (operands[0])) <= 4"
-  [(const_int 0)]
-{
-  rtx pat;
-  enum machine_mode mode = GET_MODE (operands[0]);
-
-  if (GET_MODE_SIZE (mode) < 4)
-    operands[0] = gen_lowpart (SImode, operands[0]);
-  if (mode != Pmode)
-    operands[1] = gen_lowpart (Pmode, operands[1]);
-  operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
-
-  pat = gen_rtx_MULT (Pmode, operands[1], operands[2]);
-  if (Pmode != SImode)
-    pat = gen_rtx_SUBREG (SImode, pat, 0);
-  emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
-  DONE;
-})
-
-;; Rare case of shifting RSP is handled by generating move and shift
-(define_split
-  [(set (match_operand 0 "register_operand" "")
-       (ashift (match_operand 1 "register_operand" "")
-                (match_operand:QI 2 "const_int_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "reload_completed
-   && true_regnum (operands[0]) != true_regnum (operands[1])"
-  [(const_int 0)]
-{
-  rtx pat, clob;
-  emit_move_insn (operands[0], operands[1]);
-  pat = gen_rtx_SET (VOIDmode, operands[0],
-                    gen_rtx_ASHIFT (GET_MODE (operands[0]),
-                                    operands[0], operands[2]));
-  clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
-  emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, pat, clob)));
-  DONE;
-})
+   (set_attr "mode" "HI,SI")])
 
-(define_insn "*ashlsi3_1_zext"
-  [(set (match_operand:DI 0 "register_operand" "=r,r")
-       (zero_extend:DI (ashift:SI (match_operand:SI 1 "register_operand" "0,l")
-                       (match_operand:QI 2 "nonmemory_operand" "cI,M"))))
+(define_insn "*ashlqi3_1"
+  [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
+       (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
+                  (match_operand:QI 2 "nonmemory_operand" "cI,cI")))
    (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
+  "TARGET_PARTIAL_REG_STALL
+   && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
 {
   switch (get_attr_type (insn))
     {
     case TYPE_ALU:
       gcc_assert (operands[2] == const1_rtx);
-      return "add{l}\t%k0, %k0";
-
-    case TYPE_LEA:
-      return "#";
+      if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
+        return "add{l}\t%k0, %k0";
+      else
+        return "add{b}\t%0, %0";
 
     default:
       if (REG_P (operands[2]))
-       return "sal{l}\t{%b2, %k0|%k0, %b2}";
+       {
+         if (get_attr_mode (insn) == MODE_SI)
+           return "sal{l}\t{%b2, %k0|%k0, %b2}";
+         else
+           return "sal{b}\t{%b2, %0|%0, %b2}";
+       }
       else if (operands[2] == const1_rtx
               && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{l}\t%k0";
+       {
+         if (get_attr_mode (insn) == MODE_SI)
+           return "sal{l}\t%0";
+         else
+           return "sal{b}\t%0";
+       }
       else
-       return "sal{l}\t{%2, %k0|%k0, %2}";
+       {
+         if (get_attr_mode (insn) == MODE_SI)
+           return "sal{l}\t{%2, %k0|%k0, %2}";
+         else
+           return "sal{b}\t{%2, %0|%0, %2}";
+       }
     }
 }
   [(set (attr "type")
-     (cond [(eq_attr "alternative" "1")
-             (const_string "lea")
-            (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                    (const_int 0))
+     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
+                         (const_int 0))
+                     (match_operand 0 "register_operand" ""))
                 (match_operand 2 "const1_operand" ""))
              (const_string "alu")
           ]
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "SI")])
+   (set_attr "mode" "QI,SI")])
 
-;; Convert lea to the lea pattern to avoid flags dependency.
-(define_split
-  [(set (match_operand:DI 0 "register_operand" "")
-       (zero_extend:DI (ashift (match_operand 1 "register_operand" "")
-                               (match_operand:QI 2 "const_int_operand" ""))))
+;; %%% Potential partial reg stall on alternative 2.  What to do?
+(define_insn "*ashlqi3_1_lea"
+  [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,r")
+       (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,l")
+                  (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
    (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && reload_completed
-   && true_regnum (operands[0]) != true_regnum (operands[1])"
-  [(set (match_dup 0) (zero_extend:DI
-                       (subreg:SI (mult:SI (match_dup 1)
-                                           (match_dup 2)) 0)))]
-{
-  operands[1] = gen_lowpart (Pmode, operands[1]);
-  operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
-})
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashlsi3_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
-       (ashift:SI (match_dup 1) (match_dup 2)))]
-   "(optimize_function_for_size_p (cfun)
-     || !TARGET_PARTIAL_FLAG_REG_STALL
-     || (operands[2] == const1_rtx
-        && (TARGET_SHIFT1
-            || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
+  "!TARGET_PARTIAL_REG_STALL
+   && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
 {
   switch (get_attr_type (insn))
     {
+    case TYPE_LEA:
+      return "#";
     case TYPE_ALU:
       gcc_assert (operands[2] == const1_rtx);
-      return "add{l}\t%0, %0";
+      if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
+        return "add{l}\t%k0, %k0";
+      else
+        return "add{b}\t%0, %0";
 
     default:
       if (REG_P (operands[2]))
-       return "sal{l}\t{%b2, %0|%0, %b2}";
+       {
+         if (get_attr_mode (insn) == MODE_SI)
+           return "sal{l}\t{%b2, %k0|%k0, %b2}";
+         else
+           return "sal{b}\t{%b2, %0|%0, %b2}";
+       }
       else if (operands[2] == const1_rtx
               && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{l}\t%0";
+       {
+         if (get_attr_mode (insn) == MODE_SI)
+           return "sal{l}\t%0";
+         else
+           return "sal{b}\t%0";
+       }
       else
-       return "sal{l}\t{%2, %0|%0, %2}";
+       {
+         if (get_attr_mode (insn) == MODE_SI)
+           return "sal{l}\t{%2, %k0|%k0, %2}";
+         else
+           return "sal{b}\t{%2, %0|%0, %2}";
+       }
     }
 }
   [(set (attr "type")
-     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
+     (cond [(eq_attr "alternative" "2")
+             (const_string "lea")
+            (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
                          (const_int 0))
                      (match_operand 0 "register_operand" ""))
                 (match_operand 2 "const1_operand" ""))
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "SI")])
+   (set_attr "mode" "QI,SI,SI")])
 
-(define_insn "*ashlsi3_cconly"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (clobber (match_scratch:SI 0 "=r"))]
-  "(optimize_function_for_size_p (cfun)
-    || !TARGET_PARTIAL_FLAG_REG_STALL
-    || (operands[2] == const1_rtx
-       && (TARGET_SHIFT1
-           || TARGET_DOUBLE_WITH_ADD)))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
+;; Convert lea to the lea pattern to avoid flags dependency.
+(define_split
+  [(set (match_operand:DI 0 "register_operand" "")
+       (ashift:DI (match_operand:DI 1 "index_register_operand" "")
+                  (match_operand:QI 2 "const_int_operand" "")))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_64BIT && reload_completed
+   && true_regnum (operands[0]) != true_regnum (operands[1])"
+  [(set (match_dup 0)
+       (mult:DI (match_dup 1)
+                (match_dup 2)))]
+  "operands[2] = gen_int_mode (1 << INTVAL (operands[2]), DImode);")
+
+;; Convert lea to the lea pattern to avoid flags dependency.
+(define_split
+  [(set (match_operand 0 "register_operand" "")
+       (ashift (match_operand 1 "index_register_operand" "")
+                (match_operand:QI 2 "const_int_operand" "")))
+   (clobber (reg:CC FLAGS_REG))]
+  "reload_completed
+   && true_regnum (operands[0]) != true_regnum (operands[1])
+   && GET_MODE_SIZE (GET_MODE (operands[0])) <= 4"
+  [(const_int 0)]
+{
+  rtx pat;
+  enum machine_mode mode = GET_MODE (operands[0]);
+
+  if (GET_MODE_SIZE (mode) < 4)
+    operands[0] = gen_lowpart (SImode, operands[0]);
+  if (mode != Pmode)
+    operands[1] = gen_lowpart (Pmode, operands[1]);
+  operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
+
+  pat = gen_rtx_MULT (Pmode, operands[1], operands[2]);
+  if (Pmode != SImode)
+    pat = gen_rtx_SUBREG (SImode, pat, 0);
+  emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
+  DONE;
+})
+
+;; Rare case of shifting RSP is handled by generating move and shift
+(define_split
+  [(set (match_operand 0 "register_operand" "")
+       (ashift (match_operand 1 "register_operand" "")
+                (match_operand:QI 2 "const_int_operand" "")))
+   (clobber (reg:CC FLAGS_REG))]
+  "reload_completed
+   && true_regnum (operands[0]) != true_regnum (operands[1])"
+  [(const_int 0)]
+{
+  rtx pat, clob;
+  emit_move_insn (operands[0], operands[1]);
+  pat = gen_rtx_SET (VOIDmode, operands[0],
+                    gen_rtx_ASHIFT (GET_MODE (operands[0]),
+                                    operands[0], operands[2]));
+  clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
+  emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, pat, clob)));
+  DONE;
+})
+
+;; Convert lea to the lea pattern to avoid flags dependency.
+(define_split
+  [(set (match_operand:DI 0 "register_operand" "")
+       (zero_extend:DI
+         (ashift:SI (match_operand:SI 1 "register_operand" "")
+                    (match_operand:QI 2 "const_int_operand" ""))))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_64BIT && reload_completed
+   && true_regnum (operands[0]) != true_regnum (operands[1])"
+  [(set (match_dup 0)
+       (zero_extend:DI (subreg:SI (mult:SI (match_dup 1) (match_dup 2)) 0)))]
+{
+  operands[1] = gen_lowpart (Pmode, operands[1]);
+  operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
+})
+
+;; This pattern can't accept a variable shift count, since shifts by
+;; zero don't affect the flags.  We assume that shifts by constant
+;; zero are optimized away.
+(define_insn "*ashl<mode>3_cmp"
+  [(set (reg FLAGS_REG)
+       (compare
+         (ashift:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
+                     (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
+         (const_int 0)))
+   (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
+       (ashift:SWI (match_dup 1) (match_dup 2)))]
+  "(optimize_function_for_size_p (cfun)
+    || !TARGET_PARTIAL_FLAG_REG_STALL
+    || (operands[2] == const1_rtx
+       && (TARGET_SHIFT1
+           || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
+   && ix86_match_ccmode (insn, CCGOCmode)
+   && ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
 {
   switch (get_attr_type (insn))
     {
     case TYPE_ALU:
       gcc_assert (operands[2] == const1_rtx);
-      return "add{l}\t%0, %0";
+      return "add{<imodesuffix>}\t%0, %0";
 
     default:
-      if (REG_P (operands[2]))
-       return "sal{l}\t{%b2, %0|%0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{l}\t%0";
+      if (operands[2] == const1_rtx
+         && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+       return "sal{<imodesuffix>}\t%0";
       else
-       return "sal{l}\t{%2, %0|%0, %2}";
+       return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "SI")])
+   (set_attr "mode" "<MODE>")])
 
 (define_insn "*ashlsi3_cmp_zext"
   [(set (reg FLAGS_REG)
       return "add{l}\t%k0, %k0";
 
     default:
-      if (REG_P (operands[2]))
-       return "sal{l}\t{%b2, %k0|%k0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+      if (operands[2] == const1_rtx
+         && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
        return "sal{l}\t%k0";
       else
        return "sal{l}\t{%2, %k0|%k0, %2}";
        (const_string "*")))
    (set_attr "mode" "SI")])
 
-(define_expand "ashlhi3"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "")
-       (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "")
-                  (match_operand:QI 2 "nonmemory_operand" "")))]
-  "TARGET_HIMODE_MATH"
-  "ix86_expand_binary_operator (ASHIFT, HImode, operands); DONE;")
-
-(define_insn "*ashlhi3_1_lea"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
-       (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,l")
-                  (match_operand:QI 2 "nonmemory_operand" "cI,M")))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_PARTIAL_REG_STALL
-   && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_LEA:
-      return "#";
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      return "add{w}\t%0, %0";
-
-    default:
-      if (REG_P (operands[2]))
-       return "sal{w}\t{%b2, %0|%0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{w}\t%0";
-      else
-       return "sal{w}\t{%2, %0|%0, %2}";
-    }
-}
-  [(set (attr "type")
-     (cond [(eq_attr "alternative" "1")
-             (const_string "lea")
-            (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
-                (match_operand 2 "const1_operand" ""))
-             (const_string "alu")
-          ]
-          (const_string "ishift")))
-   (set (attr "length_immediate")
-     (if_then_else
-       (ior (eq_attr "type" "alu")
-           (and (eq_attr "type" "ishift")
-                (and (match_operand 2 "const1_operand" "")
-                     (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
-                         (const_int 0)))))
-       (const_string "0")
-       (const_string "*")))
-   (set_attr "mode" "HI,SI")])
-
-(define_insn "*ashlhi3_1"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
-       (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                  (match_operand:QI 2 "nonmemory_operand" "cI")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_PARTIAL_REG_STALL
-   && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      return "add{w}\t%0, %0";
-
-    default:
-      if (REG_P (operands[2]))
-       return "sal{w}\t{%b2, %0|%0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{w}\t%0";
-      else
-       return "sal{w}\t{%2, %0|%0, %2}";
-    }
-}
-  [(set (attr "type")
-     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
-                (match_operand 2 "const1_operand" ""))
-             (const_string "alu")
-          ]
-          (const_string "ishift")))
-   (set (attr "length_immediate")
-     (if_then_else
-       (ior (eq_attr "type" "alu")
-           (and (eq_attr "type" "ishift")
-                (and (match_operand 2 "const1_operand" "")
-                     (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
-                         (const_int 0)))))
-       (const_string "0")
-       (const_string "*")))
-   (set_attr "mode" "HI")])
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashlhi3_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
-       (ashift:HI (match_dup 1) (match_dup 2)))]
-  "(optimize_function_for_size_p (cfun)
-    || !TARGET_PARTIAL_FLAG_REG_STALL
-    || (operands[2] == const1_rtx
-       && (TARGET_SHIFT1
-           || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      return "add{w}\t%0, %0";
-
-    default:
-      if (REG_P (operands[2]))
-       return "sal{w}\t{%b2, %0|%0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{w}\t%0";
-      else
-       return "sal{w}\t{%2, %0|%0, %2}";
-    }
-}
-  [(set (attr "type")
-     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
-                (match_operand 2 "const1_operand" ""))
-             (const_string "alu")
-          ]
-          (const_string "ishift")))
-   (set (attr "length_immediate")
-     (if_then_else
-       (ior (eq_attr "type" "alu")
-           (and (eq_attr "type" "ishift")
-                (and (match_operand 2 "const1_operand" "")
-                     (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
-                         (const_int 0)))))
-       (const_string "0")
-       (const_string "*")))
-   (set_attr "mode" "HI")])
-
-(define_insn "*ashlhi3_cconly"
+(define_insn "*ashl<mode>3_cconly"
   [(set (reg FLAGS_REG)
        (compare
-         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_31_operand" "I"))
+         (ashift:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
+                     (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
          (const_int 0)))
-   (clobber (match_scratch:HI 0 "=r"))]
+   (clobber (match_scratch:SWI 0 "=<r>"))]
   "(optimize_function_for_size_p (cfun)
     || !TARGET_PARTIAL_FLAG_REG_STALL
     || (operands[2] == const1_rtx
        && (TARGET_SHIFT1
            || TARGET_DOUBLE_WITH_ADD)))
    && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
+   && ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
 {
   switch (get_attr_type (insn))
     {
     case TYPE_ALU:
       gcc_assert (operands[2] == const1_rtx);
-      return "add{w}\t%0, %0";
+      return "add{<imodesuffix>}\t%0, %0";
 
     default:
-      if (REG_P (operands[2]))
-       return "sal{w}\t{%b2, %0|%0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{w}\t%0";
+      if (operands[2] == const1_rtx
+         && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+       return "sal{<imodesuffix>}\t%0";
       else
-       return "sal{w}\t{%2, %0|%0, %2}";
+       return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
                          (const_int 0)))))
        (const_string "0")
        (const_string "*")))
-   (set_attr "mode" "HI")])
+   (set_attr "mode" "<MODE>")])
 
-(define_expand "ashlqi3"
-  [(set (match_operand:QI 0 "nonimmediate_operand" "")
-       (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "")
-                  (match_operand:QI 2 "nonmemory_operand" "")))]
-  "TARGET_QIMODE_MATH"
-  "ix86_expand_binary_operator (ASHIFT, QImode, operands); DONE;")
+;; See comment above `ashldi3' about how this works.
 
-;; %%% Potential partial reg stall on alternative 2.  What to do?
-
-(define_insn "*ashlqi3_1_lea"
-  [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,r")
-       (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,l")
-                  (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_PARTIAL_REG_STALL
-   && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_LEA:
-      return "#";
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
-        return "add{l}\t%k0, %k0";
-      else
-        return "add{b}\t%0, %0";
-
-    default:
-      if (REG_P (operands[2]))
-       {
-         if (get_attr_mode (insn) == MODE_SI)
-           return "sal{l}\t{%b2, %k0|%k0, %b2}";
-         else
-           return "sal{b}\t{%b2, %0|%0, %b2}";
-       }
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       {
-         if (get_attr_mode (insn) == MODE_SI)
-           return "sal{l}\t%0";
-         else
-           return "sal{b}\t%0";
-       }
-      else
-       {
-         if (get_attr_mode (insn) == MODE_SI)
-           return "sal{l}\t{%2, %k0|%k0, %2}";
-         else
-           return "sal{b}\t{%2, %0|%0, %2}";
-       }
-    }
-}
-  [(set (attr "type")
-     (cond [(eq_attr "alternative" "2")
-             (const_string "lea")
-            (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
-                (match_operand 2 "const1_operand" ""))
-             (const_string "alu")
-          ]
-          (const_string "ishift")))
-   (set (attr "length_immediate")
-     (if_then_else
-       (ior (eq_attr "type" "alu")
-           (and (eq_attr "type" "ishift")
-                (and (match_operand 2 "const1_operand" "")
-                     (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
-                         (const_int 0)))))
-       (const_string "0")
-       (const_string "*")))
-   (set_attr "mode" "QI,SI,SI")])
-
-(define_insn "*ashlqi3_1"
-  [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
-       (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
-                  (match_operand:QI 2 "nonmemory_operand" "cI,cI")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_PARTIAL_REG_STALL
-   && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
-        return "add{l}\t%k0, %k0";
-      else
-        return "add{b}\t%0, %0";
-
-    default:
-      if (REG_P (operands[2]))
-       {
-         if (get_attr_mode (insn) == MODE_SI)
-           return "sal{l}\t{%b2, %k0|%k0, %b2}";
-         else
-           return "sal{b}\t{%b2, %0|%0, %b2}";
-       }
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       {
-         if (get_attr_mode (insn) == MODE_SI)
-           return "sal{l}\t%0";
-         else
-           return "sal{b}\t%0";
-       }
-      else
-       {
-         if (get_attr_mode (insn) == MODE_SI)
-           return "sal{l}\t{%2, %k0|%k0, %2}";
-         else
-           return "sal{b}\t{%2, %0|%0, %2}";
-       }
-    }
-}
-  [(set (attr "type")
-     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
-                (match_operand 2 "const1_operand" ""))
-             (const_string "alu")
-          ]
-          (const_string "ishift")))
-   (set (attr "length_immediate")
-     (if_then_else
-       (ior (eq_attr "type" "alu")
-           (and (eq_attr "type" "ishift")
-                (and (match_operand 2 "const1_operand" "")
-                     (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
-                         (const_int 0)))))
-       (const_string "0")
-       (const_string "*")))
-   (set_attr "mode" "QI,SI")])
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashlqi3_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
-       (ashift:QI (match_dup 1) (match_dup 2)))]
-  "(optimize_function_for_size_p (cfun)
-    || !TARGET_PARTIAL_FLAG_REG_STALL
-    || (operands[2] == const1_rtx
-       && (TARGET_SHIFT1
-           || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      return "add{b}\t%0, %0";
-
-    default:
-      if (REG_P (operands[2]))
-       return "sal{b}\t{%b2, %0|%0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{b}\t%0";
-      else
-       return "sal{b}\t{%2, %0|%0, %2}";
-    }
-}
-  [(set (attr "type")
-     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
-                (match_operand 2 "const1_operand" ""))
-             (const_string "alu")
-          ]
-          (const_string "ishift")))
-   (set (attr "length_immediate")
-     (if_then_else
-       (ior (eq_attr "type" "alu")
-           (and (eq_attr "type" "ishift")
-                (and (match_operand 2 "const1_operand" "")
-                     (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
-                         (const_int 0)))))
-       (const_string "0")
-       (const_string "*")))
-   (set_attr "mode" "QI")])
-
-(define_insn "*ashlqi3_cconly"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (clobber (match_scratch:QI 0 "=q"))]
-  "(optimize_function_for_size_p (cfun)
-    || !TARGET_PARTIAL_FLAG_REG_STALL
-    || (operands[2] == const1_rtx
-       && (TARGET_SHIFT1
-           || TARGET_DOUBLE_WITH_ADD)))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
-{
-  switch (get_attr_type (insn))
-    {
-    case TYPE_ALU:
-      gcc_assert (operands[2] == const1_rtx);
-      return "add{b}\t%0, %0";
-
-    default:
-      if (REG_P (operands[2]))
-       return "sal{b}\t{%b2, %0|%0, %b2}";
-      else if (operands[2] == const1_rtx
-              && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
-       return "sal{b}\t%0";
-      else
-       return "sal{b}\t{%2, %0|%0, %2}";
-    }
-}
-  [(set (attr "type")
-     (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
-                         (const_int 0))
-                     (match_operand 0 "register_operand" ""))
-                (match_operand 2 "const1_operand" ""))
-             (const_string "alu")
-          ]
-          (const_string "ishift")))
-   (set (attr "length_immediate")
-     (if_then_else
-       (ior (eq_attr "type" "alu")
-           (and (eq_attr "type" "ishift")
-                (and (match_operand 2 "const1_operand" "")
-                     (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
-                         (const_int 0)))))
-       (const_string "0")
-       (const_string "*")))
-   (set_attr "mode" "QI")])
-
-;; See comment above `ashldi3' about how this works.
-
-(define_expand "ashrti3"
-  [(set (match_operand:TI 0 "register_operand" "")
-       (ashiftrt:TI (match_operand:TI 1 "register_operand" "")
-                    (match_operand:QI 2 "nonmemory_operand" "")))]
-  "TARGET_64BIT"
-  "ix86_expand_binary_operator (ASHIFTRT, TImode, operands); DONE;")
-
-(define_insn "*ashrti3_1"
-  [(set (match_operand:TI 0 "register_operand" "=r")
-       (ashiftrt:TI (match_operand:TI 1 "register_operand" "0")
-                    (match_operand:QI 2 "nonmemory_operand" "Oc")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT"
-  "#"
-  [(set_attr "type" "multi")])
-
-(define_peephole2
-  [(match_scratch:DI 3 "r")
-   (parallel [(set (match_operand:TI 0 "register_operand" "")
-                  (ashiftrt:TI (match_operand:TI 1 "register_operand" "")
-                               (match_operand:QI 2 "nonmemory_operand" "")))
-             (clobber (reg:CC FLAGS_REG))])
-   (match_dup 3)]
-  "TARGET_64BIT"
-  [(const_int 0)]
-  "ix86_split_ashr (operands, operands[3], TImode); DONE;")
-
-(define_split
-  [(set (match_operand:TI 0 "register_operand" "")
-       (ashiftrt:TI (match_operand:TI 1 "register_operand" "")
-                    (match_operand:QI 2 "nonmemory_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
-                   ? epilogue_completed : reload_completed)"
-  [(const_int 0)]
-  "ix86_split_ashr (operands, NULL_RTX, TImode); DONE;")
-
-(define_insn "x86_64_shrd"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
-        (ior:DI (ashiftrt:DI (match_dup 0)
-                 (match_operand:QI 2 "nonmemory_operand" "Jc"))
-               (ashift:DI (match_operand:DI 1 "register_operand" "r")
-                 (minus:QI (const_int 64) (match_dup 2)))))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT"
-  "shrd{q}\t{%s2%1, %0|%0, %1, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "prefix_0f" "1")
-   (set_attr "mode" "DI")
-   (set_attr "athlon_decode" "vector")
-   (set_attr "amdfam10_decode" "vector")])
-
-(define_expand "ashrdi3"
-  [(set (match_operand:DI 0 "shiftdi_operand" "")
-       (ashiftrt:DI (match_operand:DI 1 "shiftdi_operand" "")
-                    (match_operand:QI 2 "nonmemory_operand" "")))]
-  ""
-  "ix86_expand_binary_operator (ASHIFTRT, DImode, operands); DONE;")
-
-(define_expand "x86_64_shift_adj_3"
-  [(use (match_operand:DI 0 "register_operand" ""))
-   (use (match_operand:DI 1 "register_operand" ""))
-   (use (match_operand:QI 2 "register_operand" ""))]
-  ""
-{
-  rtx label = gen_label_rtx ();
-  rtx tmp;
-
-  emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (64)));
-
-  tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
-  tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
-  tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
-                             gen_rtx_LABEL_REF (VOIDmode, label),
-                             pc_rtx);
-  tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
-  JUMP_LABEL (tmp) = label;
-
-  emit_move_insn (operands[0], operands[1]);
-  emit_insn (gen_ashrdi3_63_rex64 (operands[1], operands[1], GEN_INT (63)));
-
-  emit_label (label);
-  LABEL_NUSES (label) = 1;
-
-  DONE;
-})
-
-(define_insn "ashrdi3_63_rex64"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
-       (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
-                    (match_operand:DI 2 "const_int_operand" "i,i")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && INTVAL (operands[2]) == 63
-   && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
-  "@
-   {cqto|cqo}
-   sar{q}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "imovx,ishift")
-   (set_attr "prefix_0f" "0,*")
-   (set_attr "length_immediate" "0,*")
-   (set_attr "modrm" "0,1")
-   (set_attr "mode" "DI")])
-
-(define_insn "*ashrdi3_1_one_bit_rex64"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const1_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT
-   && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
-  "sar{q}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "DI")])
-
-(define_insn "*ashrdi3_1_rex64"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
-       (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
-                    (match_operand:QI 2 "nonmemory_operand" "J,c")))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
-  "@
-   sar{q}\t{%2, %0|%0, %2}
-   sar{q}\t{%b2, %0|%0, %b2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "DI")])
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashrdi3_one_bit_cmp_rex64"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
-         (const_int 0)))
-   (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:DI (match_dup 1) (match_dup 2)))]
-  "TARGET_64BIT
-   && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
-  "sar{q}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "DI")])
-
-(define_insn "*ashrdi3_one_bit_cconly_rex64"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
-         (const_int 0)))
-   (clobber (match_scratch:DI 0 "=r"))]
-  "TARGET_64BIT
-   && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
-  "sar{q}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "DI")])
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashrdi3_cmp_rex64"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const_1_to_63_operand" "J"))
-         (const_int 0)))
-   (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:DI (match_dup 1) (match_dup 2)))]
-  "TARGET_64BIT
-   && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
-  "sar{q}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "DI")])
-
-(define_insn "*ashrdi3_cconly_rex64"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const_1_to_63_operand" "J"))
-         (const_int 0)))
-   (clobber (match_scratch:DI 0 "=r"))]
-  "TARGET_64BIT
-   && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
-  "sar{q}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "DI")])
+(define_expand "ashr<mode>3"
+  [(set (match_operand:SDWIM 0 "<shift_operand>" "")
+       (ashiftrt:SDWIM (match_operand:SDWIM 1 "<shift_operand>" "")
+                       (match_operand:QI 2 "nonmemory_operand" "")))]
+  ""
+  "ix86_expand_binary_operator (ASHIFTRT, <MODE>mode, operands); DONE;")
 
-(define_insn "*ashrdi3_1"
-  [(set (match_operand:DI 0 "register_operand" "=r")
-       (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
-                    (match_operand:QI 2 "nonmemory_operand" "Jc")))
+(define_insn_and_split "*ashr<mode>3_doubleword"
+  [(set (match_operand:DWI 0 "register_operand" "=r")
+       (ashiftrt:DWI (match_operand:DWI 1 "register_operand" "0")
+                     (match_operand:QI 2 "nonmemory_operand" "<S>c")))
    (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT"
+  ""
   "#"
+  "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
+  [(const_int 0)]
+  "ix86_split_ashr (operands, NULL_RTX, <MODE>mode); DONE;"
   [(set_attr "type" "multi")])
 
-;; By default we don't ask for a scratch register, because when DImode
+;; By default we don't ask for a scratch register, because when DWImode
 ;; values are manipulated, registers are already at a premium.  But if
 ;; we have one handy, we won't turn it away.
+
 (define_peephole2
-  [(match_scratch:SI 3 "r")
-   (parallel [(set (match_operand:DI 0 "register_operand" "")
-                  (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
-                               (match_operand:QI 2 "nonmemory_operand" "")))
+  [(match_scratch:DWIH 3 "r")
+   (parallel [(set (match_operand:<DWI> 0 "register_operand" "")
+                  (ashiftrt:<DWI>
+                    (match_operand:<DWI> 1 "register_operand" "")
+                    (match_operand:QI 2 "nonmemory_operand" "")))
              (clobber (reg:CC FLAGS_REG))])
    (match_dup 3)]
-  "!TARGET_64BIT && TARGET_CMOVE"
+  "TARGET_CMOVE"
   [(const_int 0)]
-  "ix86_split_ashr (operands, operands[3], DImode); DONE;")
+  "ix86_split_ashr (operands, operands[3], <DWI>mode); DONE;")
 
-(define_split
-  [(set (match_operand:DI 0 "register_operand" "")
-       (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
-                    (match_operand:QI 2 "nonmemory_operand" "")))
+(define_insn "x86_64_shrd"
+  [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
+        (ior:DI (ashiftrt:DI (match_dup 0)
+                 (match_operand:QI 2 "nonmemory_operand" "Jc"))
+               (ashift:DI (match_operand:DI 1 "register_operand" "r")
+                 (minus:QI (const_int 64) (match_dup 2)))))
    (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT && ((optimize > 0 && flag_peephole2)
-                    ? epilogue_completed : reload_completed)"
-  [(const_int 0)]
-  "ix86_split_ashr (operands, NULL_RTX, DImode); DONE;")
+  "TARGET_64BIT"
+  "shrd{q}\t{%s2%1, %0|%0, %1, %2}"
+  [(set_attr "type" "ishift")
+   (set_attr "prefix_0f" "1")
+   (set_attr "mode" "DI")
+   (set_attr "athlon_decode" "vector")
+   (set_attr "amdfam10_decode" "vector")])
 
 (define_insn "x86_shrd"
   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
    (set_attr "pent_pair" "np")
    (set_attr "mode" "SI")])
 
-(define_expand "x86_shift_adj_3"
-  [(use (match_operand:SI 0 "register_operand" ""))
-   (use (match_operand:SI 1 "register_operand" ""))
-   (use (match_operand:QI 2 "register_operand" ""))]
-  ""
-{
-  rtx label = gen_label_rtx ();
-  rtx tmp;
-
-  emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
-
-  tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
-  tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
-  tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
-                             gen_rtx_LABEL_REF (VOIDmode, label),
-                             pc_rtx);
-  tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
-  JUMP_LABEL (tmp) = label;
-
-  emit_move_insn (operands[0], operands[1]);
-  emit_insn (gen_ashrsi3_31 (operands[1], operands[1], GEN_INT (31)));
-
-  emit_label (label);
-  LABEL_NUSES (label) = 1;
-
-  DONE;
-})
-
-(define_expand "ashrsi3_31"
-  [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
-                  (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
-                               (match_operand:SI 2 "const_int_operand" "i,i")))
-              (clobber (reg:CC FLAGS_REG))])]
-  "")
-
-(define_insn "*ashrsi3_31"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
-       (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
-                    (match_operand:SI 2 "const_int_operand" "i,i")))
-   (clobber (reg:CC FLAGS_REG))]
-  "INTVAL (operands[2]) == 31
-   && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "@
-   {cltd|cdq}
-   sar{l}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "imovx,ishift")
-   (set_attr "prefix_0f" "0,*")
-   (set_attr "length_immediate" "0,*")
-   (set_attr "modrm" "0,1")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_31_zext"
-  [(set (match_operand:DI 0 "register_operand" "=*d,r")
-       (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
-                                    (match_operand:SI 2 "const_int_operand" "i,i"))))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
-   && INTVAL (operands[2]) == 31
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "@
-   {cltd|cdq}
-   sar{l}\t{%2, %k0|%k0, %2}"
-  [(set_attr "type" "imovx,ishift")
-   (set_attr "prefix_0f" "0,*")
-   (set_attr "length_immediate" "0,*")
-   (set_attr "modrm" "0,1")
-   (set_attr "mode" "SI")])
-
-(define_expand "ashrsi3"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "")
-       (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "")
-                    (match_operand:QI 2 "nonmemory_operand" "")))]
-  ""
-  "ix86_expand_binary_operator (ASHIFTRT, SImode, operands); DONE;")
-
-(define_insn "*ashrsi3_1_one_bit"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const1_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_1_one_bit_zext"
-  [(set (match_operand:DI 0 "register_operand" "=r")
-       (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
-                                    (match_operand:QI 2 "const1_operand" ""))))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT
-   && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t%k0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_1"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
-       (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
-                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
-   (clobber (reg:CC FLAGS_REG))]
-  "ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "@
-   sar{l}\t{%2, %0|%0, %2}
-   sar{l}\t{%b2, %0|%0, %b2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_1_zext"
-  [(set (match_operand:DI 0 "register_operand" "=r,r")
-       (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0")
-                                    (match_operand:QI 2 "nonmemory_operand" "I,c"))))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "@
-   sar{l}\t{%2, %k0|%k0, %2}
-   sar{l}\t{%b2, %k0|%k0, %b2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "SI")])
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashrsi3_one_bit_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
-         (const_int 0)))
-   (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:SI (match_dup 1) (match_dup 2)))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_one_bit_cconly"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
-         (const_int 0)))
-   (clobber (match_scratch:SI 0 "=r"))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_one_bit_cmp_zext"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
-         (const_int 0)))
-   (set (match_operand:DI 0 "register_operand" "=r")
-       (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
-  "TARGET_64BIT
-   && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t%k0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "SI")])
-
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashrsi3_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:SI (match_dup 1) (match_dup 2)))]
-  "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_cconly"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (clobber (match_scratch:SI 0 "=r"))]
-  "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "SI")])
-
-(define_insn "*ashrsi3_cmp_zext"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
-                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (set (match_operand:DI 0 "register_operand" "=r")
-       (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
-  "TARGET_64BIT
-   && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
-  "sar{l}\t{%2, %k0|%k0, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "SI")])
-
-(define_expand "ashrhi3"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "")
-       (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "")
-                    (match_operand:QI 2 "nonmemory_operand" "")))]
-  "TARGET_HIMODE_MATH"
-  "ix86_expand_binary_operator (ASHIFTRT, HImode, operands); DONE;")
+(define_insn "ashrdi3_cvt"
+  [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
+       (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
+                    (match_operand:QI 2 "const_int_operand" "")))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_64BIT && INTVAL (operands[2]) == 63
+   && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
+   && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
+  "@
+   {cqto|cqo}
+   sar{q}\t{%2, %0|%0, %2}"
+  [(set_attr "type" "imovx,ishift")
+   (set_attr "prefix_0f" "0,*")
+   (set_attr "length_immediate" "0,*")
+   (set_attr "modrm" "0,1")
+   (set_attr "mode" "DI")])
 
-(define_insn "*ashrhi3_1_one_bit"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const1_operand" "")))
+(define_insn "*ashrsi3_cvt_zext"
+  [(set (match_operand:DI 0 "register_operand" "=*d,r")
+       (zero_extend:DI
+         (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
+                      (match_operand:QI 2 "const_int_operand" ""))))
    (clobber (reg:CC FLAGS_REG))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
-  "sar{w}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "HI")])
+  "TARGET_64BIT && INTVAL (operands[2]) == 31
+   && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
+   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
+  "@
+   {cltd|cdq}
+   sar{l}\t{%2, %k0|%k0, %2}"
+  [(set_attr "type" "imovx,ishift")
+   (set_attr "prefix_0f" "0,*")
+   (set_attr "length_immediate" "0,*")
+   (set_attr "modrm" "0,1")
+   (set_attr "mode" "SI")])
 
-(define_insn "*ashrhi3_1"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
-       (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
-                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
+(define_insn "ashrsi3_cvt"
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
+       (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
+                    (match_operand:QI 2 "const_int_operand" "")))
    (clobber (reg:CC FLAGS_REG))]
-  "ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
+  "INTVAL (operands[2]) == 31
+   && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
+   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
   "@
-   sar{w}\t{%2, %0|%0, %2}
-   sar{w}\t{%b2, %0|%0, %b2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "HI")])
+   {cltd|cdq}
+   sar{l}\t{%2, %0|%0, %2}"
+  [(set_attr "type" "imovx,ishift")
+   (set_attr "prefix_0f" "0,*")
+   (set_attr "length_immediate" "0,*")
+   (set_attr "modrm" "0,1")
+   (set_attr "mode" "SI")])
 
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashrhi3_one_bit_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
-         (const_int 0)))
-   (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:HI (match_dup 1) (match_dup 2)))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
-  "sar{w}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "HI")])
+(define_expand "x86_shift<mode>_adj_3"
+  [(use (match_operand:SWI48 0 "register_operand" ""))
+   (use (match_operand:SWI48 1 "register_operand" ""))
+   (use (match_operand:QI 2 "register_operand" ""))]
+  ""
+{
+  rtx label = gen_label_rtx ();
+  rtx tmp;
 
-(define_insn "*ashrhi3_one_bit_cconly"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
-         (const_int 0)))
-   (clobber (match_scratch:HI 0 "=r"))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
-  "sar{w}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "HI")])
+  emit_insn (gen_testqi_ccz_1 (operands[2],
+                              GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
 
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashrhi3_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
-       (ashiftrt:HI (match_dup 1) (match_dup 2)))]
-  "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
-  "sar{w}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "HI")])
+  tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
+  tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
+  tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
+                             gen_rtx_LABEL_REF (VOIDmode, label),
+                             pc_rtx);
+  tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
+  JUMP_LABEL (tmp) = label;
 
-(define_insn "*ashrhi3_cconly"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
-         (const_int 0)))
-   (clobber (match_scratch:HI 0 "=r"))]
-  "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
-  "sar{w}\t{%2, %0|%0, %2}"
-  [(set_attr "type" "ishift")
-   (set_attr "mode" "HI")])
+  emit_move_insn (operands[0], operands[1]);
+  emit_insn (gen_ashr<mode>3_cvt (operands[1], operands[1],
+                                 GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1)));
+  emit_label (label);
+  LABEL_NUSES (label) = 1;
 
-(define_expand "ashrqi3"
-  [(set (match_operand:QI 0 "nonimmediate_operand" "")
-       (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "")
-                    (match_operand:QI 2 "nonmemory_operand" "")))]
-  "TARGET_QIMODE_MATH"
-  "ix86_expand_binary_operator (ASHIFTRT, QImode, operands); DONE;")
+  DONE;
+})
 
-(define_insn "*ashrqi3_1_one_bit"
-  [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
-       (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
-                    (match_operand:QI 2 "const1_operand" "")))
+(define_insn "*ashr<mode>3_1"
+  [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
+       (ashiftrt:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
+                     (match_operand:QI 2 "nonmemory_operand" "c<S>")))
    (clobber (reg:CC FLAGS_REG))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
-  "sar{b}\t%0"
+  "ix86_binary_operator_ok (ASHIFTRT, <MODE>mode, operands)"
+{
+  if (REG_P (operands[2]))
+    return "sar{<imodesuffix>}\t{%b2, %0|%0, %b2}";
+  else if (operands[2] == const1_rtx
+          && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+    return "sar{<imodesuffix>}\t%0";
+  else
+    return "sar{<imodesuffix>}\t{%2, %0|%0, %2}";
+}
   [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "QI")])
-
-(define_insn "*ashrqi3_1_one_bit_slp"
-  [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
-       (ashiftrt:QI (match_dup 0)
-                    (match_operand:QI 1 "const1_operand" "")))
-   (clobber (reg:CC FLAGS_REG))]
-  "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
-   && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
-  "sar{b}\t%0"
-  [(set_attr "type" "ishift1")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "QI")])
+   (set (attr "length_immediate")
+     (if_then_else
+       (and (match_operand 2 "const1_operand" "")
+           (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
+               (const_int 0)))
+       (const_string "0")
+       (const_string "*")))
+   (set_attr "mode" "<MODE>")])
 
-(define_insn "*ashrqi3_1"
-  [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
-       (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
-                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
+(define_insn "*ashrsi3_1_zext"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+       (zero_extend:DI
+         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
+                      (match_operand:QI 2 "nonmemory_operand" "cI"))))
    (clobber (reg:CC FLAGS_REG))]
-  "ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
-  "@
-   sar{b}\t{%2, %0|%0, %2}
-   sar{b}\t{%b2, %0|%0, %b2}"
+  "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
+{
+  if (REG_P (operands[2]))
+    return "sar{l}\t{%b2, %k0|%k0, %b2}";
+  else if (operands[2] == const1_rtx
+          && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+    return "sar{l}\t%k0";
+  else
+    return "sar{l}\t{%2, %k0|%k0, %2}";
+}
   [(set_attr "type" "ishift")
-   (set_attr "mode" "QI")])
+   (set (attr "length_immediate")
+     (if_then_else
+       (and (match_operand 2 "const1_operand" "")
+           (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
+               (const_int 0)))
+       (const_string "0")
+       (const_string "*")))
+   (set_attr "mode" "SI")])
 
 (define_insn "*ashrqi3_1_slp"
-  [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
+  [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
        (ashiftrt:QI (match_dup 0)
-                    (match_operand:QI 1 "nonmemory_operand" "I,c")))
+                    (match_operand:QI 1 "nonmemory_operand" "cI")))
    (clobber (reg:CC FLAGS_REG))]
-  "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
-   && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
-  "@
-   sar{b}\t{%1, %0|%0, %1}
-   sar{b}\t{%b1, %0|%0, %b1}"
+  "(optimize_function_for_size_p (cfun)
+    || !TARGET_PARTIAL_REG_STALL
+    || (operands[1] == const1_rtx
+       && TARGET_SHIFT1))"
+{
+  if (REG_P (operands[1]))
+    return "sar{b}\t{%b1, %0|%0, %b1}";
+  else if (operands[1] == const1_rtx
+          && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+    return "sar{b}\t%0";
+  else
+    return "sar{b}\t{%1, %0|%0, %1}";
+}
   [(set_attr "type" "ishift1")
+   (set (attr "length_immediate")
+     (if_then_else
+       (and (match_operand 1 "const1_operand" "")
+           (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
+               (const_int 0)))
+       (const_string "0")
+       (const_string "*")))
    (set_attr "mode" "QI")])
 
 ;; This pattern can't accept a variable shift count, since shifts by
 ;; zero don't affect the flags.  We assume that shifts by constant
 ;; zero are optimized away.
-(define_insn "*ashrqi3_one_bit_cmp"
-  [(set (reg FLAGS_REG)
-       (compare
-         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" "I"))
-         (const_int 0)))
-   (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
-       (ashiftrt:QI (match_dup 1) (match_dup 2)))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
-   && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
-  "sar{b}\t%0"
-  [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "QI")])
-
-(define_insn "*ashrqi3_one_bit_cconly"
+(define_insn "*ashr<mode>3_cmp"
   [(set (reg FLAGS_REG)
        (compare
-         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const1_operand" ""))
+         (ashiftrt:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
+                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
          (const_int 0)))
-   (clobber (match_scratch:QI 0 "=q"))]
-  "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
+   (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
+       (ashiftrt:SWI (match_dup 1) (match_dup 2)))]
+  "(optimize_function_for_size_p (cfun)
+    || !TARGET_PARTIAL_FLAG_REG_STALL
+    || (operands[2] == const1_rtx
+       && TARGET_SHIFT1))
    && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
-  "sar{b}\t%0"
+   && ix86_binary_operator_ok (ASHIFTRT, <MODE>mode, operands)"
+{
+  if (operands[2] == const1_rtx
+      && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+    return "sar{<imodesuffix>}\t%0";
+  else
+    return "sar{<imodesuffix>}\t{%2, %0|%0, %2}";
+}
   [(set_attr "type" "ishift")
-   (set_attr "length_immediate" "0")
-   (set_attr "mode" "QI")])
+   (set (attr "length_immediate")
+     (if_then_else
+       (and (match_operand 2 "const1_operand" "")
+           (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
+               (const_int 0)))
+       (const_string "0")
+       (const_string "*")))
+   (set_attr "mode" "<MODE>")])
 
-;; This pattern can't accept a variable shift count, since shifts by
-;; zero don't affect the flags.  We assume that shifts by constant
-;; zero are optimized away.
-(define_insn "*ashrqi3_cmp"
+(define_insn "*ashrsi3_cmp_zext"
   [(set (reg FLAGS_REG)
        (compare
-         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
+         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
                       (match_operand:QI 2 "const_1_to_31_operand" "I"))
          (const_int 0)))
-   (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
-       (ashiftrt:QI (match_dup 1) (match_dup 2)))]
-  "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
+   (set (match_operand:DI 0 "register_operand" "=r")
+       (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
+  "TARGET_64BIT
+   && (optimize_function_for_size_p (cfun)
+       || !TARGET_PARTIAL_FLAG_REG_STALL
+       || (operands[2] == const1_rtx
+          && TARGET_SHIFT1))
    && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
-  "sar{b}\t{%2, %0|%0, %2}"
+   && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
+{
+  if (operands[2] == const1_rtx
+      && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+    return "sar{l}\t%k0";
+  else
+    return "sar{l}\t{%2, %k0|%k0, %2}";
+}
   [(set_attr "type" "ishift")
-   (set_attr "mode" "QI")])
+   (set (attr "length_immediate")
+     (if_then_else
+       (and (match_operand 2 "const1_operand" "")
+           (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
+               (const_int 0)))
+       (const_string "0")
+       (const_string "*")))
+   (set_attr "mode" "SI")])
 
-(define_insn "*ashrqi3_cconly"
+(define_insn "*ashr<mode>3_cconly"
   [(set (reg FLAGS_REG)
        (compare
-         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
-                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
+         (ashiftrt:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
+                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
          (const_int 0)))
-   (clobber (match_scratch:QI 0 "=q"))]
-  "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
+   (clobber (match_scratch:DI 0 "=<r>"))]
+  "(optimize_function_for_size_p (cfun)
+    || !TARGET_PARTIAL_FLAG_REG_STALL
+    || (operands[2] == const1_rtx
+       && TARGET_SHIFT1))
    && ix86_match_ccmode (insn, CCGOCmode)
-   && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
-  "sar{b}\t{%2, %0|%0, %2}"
+   && ix86_binary_operator_ok (ASHIFTRT, <MODE>mode, operands)"
+{
+  if (operands[2] == const1_rtx
+      && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+    return "sar{<imodesuffix>}\t%0";
+  else
+    return "sar{<imodesuffix>}\t{%2, %0|%0, %2}";
+}
   [(set_attr "type" "ishift")
-   (set_attr "mode" "QI")])
-
+   (set (attr "length_immediate")
+     (if_then_else
+       (and (match_operand 2 "const1_operand" "")
+           (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
+               (const_int 0)))
+       (const_string "0")
+       (const_string "*")))
+   (set_attr "mode" "<MODE>")])
 \f
 ;; Logical shift instructions
 
    (clobber (match_scratch:SI 5 "=c"))
    (clobber (reg:CC FLAGS_REG))]
   "!TARGET_64BIT && TARGET_GNU_TLS"
-  "lea{l}\t{%a2@TLSGD(,%1,1), %0|%0, %a2@TLSGD[%1*1]}\;call\t%P3"
+  "lea{l}\t{%a2@tlsgd(,%1,1), %0|%0, %a2@tlsgd[%1*1]}\;call\t%P3"
   [(set_attr "type" "multi")
    (set_attr "length" "12")])
 
-(define_insn "*tls_global_dynamic_32_sun"
-  [(set (match_operand:SI 0 "register_operand" "=a")
-       (unspec:SI [(match_operand:SI 1 "register_operand" "b")
-                   (match_operand:SI 2 "tls_symbolic_operand" "")
-                   (match_operand:SI 3 "call_insn_operand" "")]
-                   UNSPEC_TLS_GD))
-   (clobber (match_scratch:SI 4 "=d"))
-   (clobber (match_scratch:SI 5 "=c"))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT && TARGET_SUN_TLS"
-  "lea{l}\t{%a2@DTLNDX(%1), %4|%4, %a2@DTLNDX[%1]}
-       push{l}\t%4\;call\t%a2@TLSPLT\;pop{l}\t%4\;nop"
-  [(set_attr "type" "multi")
-   (set_attr "length" "14")])
-
 (define_expand "tls_global_dynamic_32"
   [(parallel [(set (match_operand:SI 0 "register_operand" "")
                   (unspec:SI
    (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
              UNSPEC_TLS_GD)]
   "TARGET_64BIT"
-  { return ASM_BYTE "0x66\n\tlea{q}\t{%a1@TLSGD(%%rip), %%rdi|rdi, %a1@TLSGD[rip]}\n" ASM_SHORT "0x6666\n\trex64\n\tcall\t%P2"; }
+  { return ASM_BYTE "0x66\n\tlea{q}\t{%a1@tlsgd(%%rip), %%rdi|rdi, %a1@tlsgd[rip]}\n" ASM_SHORT "0x6666\n\trex64\n\tcall\t%P2"; }
   [(set_attr "type" "multi")
    (set_attr "length" "16")])
 
    (clobber (match_scratch:SI 4 "=c"))
    (clobber (reg:CC FLAGS_REG))]
   "!TARGET_64BIT && TARGET_GNU_TLS"
-  "lea{l}\t{%&@TLSLDM(%1), %0|%0, %&@TLSLDM[%1]}\;call\t%P2"
+  "lea{l}\t{%&@tlsldm(%1), %0|%0, %&@tlsldm[%1]}\;call\t%P2"
   [(set_attr "type" "multi")
    (set_attr "length" "11")])
 
-(define_insn "*tls_local_dynamic_base_32_sun"
-  [(set (match_operand:SI 0 "register_operand" "=a")
-       (unspec:SI [(match_operand:SI 1 "register_operand" "b")
-                    (match_operand:SI 2 "call_insn_operand" "")]
-                  UNSPEC_TLS_LD_BASE))
-   (clobber (match_scratch:SI 3 "=d"))
-   (clobber (match_scratch:SI 4 "=c"))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT && TARGET_SUN_TLS"
-  "lea{l}\t{%&@TMDNX(%1), %3|%3, %&@TMDNX[%1]}
-       push{l}\t%3\;call\t%&@TLSPLT\;pop{l}\t%3"
-  [(set_attr "type" "multi")
-   (set_attr "length" "13")])
-
 (define_expand "tls_local_dynamic_base_32"
   [(parallel [(set (match_operand:SI 0 "register_operand" "")
                   (unspec:SI [(match_dup 1) (match_dup 2)]
                 (match_operand:DI 2 "" "")))
    (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)]
   "TARGET_64BIT"
-  "lea{q}\t{%&@TLSLD(%%rip), %%rdi|rdi, %&@TLSLD[rip]}\;call\t%P1"
+  "lea{q}\t{%&@tlsld(%%rip), %%rdi|rdi, %&@tlsld[rip]}\;call\t%P1"
   [(set_attr "type" "multi")
    (set_attr "length" "12")])