--- /gcc/config/h8300/h8300.md	2008-07-12 04:21:25.000000000 +0530
+++ /gcc/config/h8300/h8300.md	2008-10-30 15:01:34.000000000 +0530
@@ -221,7 +221,7 @@
 	(match_operand:QI 1 "general_operand_src" "P4>X,rQi"))]
   "TARGET_H8300SX"
   "@
-    mov.b	%X1,%X0
+    mov.b	%X1:4,%X0
     mov.b	%X1,%X0"
   [(set_attr "length_table" "mov_imm4,movb")
    (set_attr "cc" "set_znv")])
@@ -299,8 +299,8 @@
   "TARGET_H8300SX"
   "@
    sub.w	%T0,%T0
-   mov.w	%T1,%T0
-   mov.w	%T1,%T0
+   mov.w	%T1:3,%T0
+   mov.w	%T1:4,%T0
    mov.w	%T1,%T0
    mov.w	%T1,%T0"
   [(set_attr "length_table" "*,*,mov_imm4,short_immediate,movw")
@@ -510,7 +510,7 @@
   "TARGET_H8300SX"
   "@
    sub.l	%S0,%S0
-   mov.l	%S1,%S0
+   mov.l	%S1:3,%S0
    mov.l	%S1,%S0
    mov.l	%S1,%S0
    clrmac
@@ -1142,7 +1142,21 @@
 	(compare (match_operand:HI 0 "h8300_dst_operand" "rU,rQ")
 		 (match_operand:HI 1 "h8300_src_operand" "P3>X,rQi")))]
   "TARGET_H8300H || TARGET_H8300S"
-  "cmp.w	%T1,%T0"
+  "*
+{
+  switch (which_alternative)
+    {
+    case 0:
+      if (!TARGET_H8300SX)
+  	return \"cmp.w	%T1,%T0\";
+      else
+  	return \"cmp.w	%T1:3,%T0\";
+      case 1:
+        return \"cmp.w	%T1,%T0\";
+      default:
+        gcc_unreachable ();
+      }
+}"
   [(set_attr "length_table" "short_immediate,addw")
    (set_attr "cc" "compare,compare")])
 
@@ -1151,7 +1165,21 @@
 	(compare (match_operand:SI 0 "h8300_dst_operand" "r,rQ")
 		 (match_operand:SI 1 "h8300_src_operand" "P3>X,rQi")))]
   "TARGET_H8300H || TARGET_H8300S"
-  "cmp.l	%S1,%S0"
+  "*
+{
+  switch (which_alternative)
+    {
+    case 0:
+      if (!TARGET_H8300SX)
+	return \"cmp.l	%S1,%S0\";
+      else
+	return \"cmp.l	%S1:3,%S0\";
+    case 1:
+      return \"cmp.l	%S1,%S0\";
+    default:
+      gcc_unreachable ();
+    }
+}"
   [(set_attr "length" "2,*")
    (set_attr "length_table" "*,addl")
    (set_attr "cc" "compare,compare")])
@@ -1258,8 +1286,8 @@
 		 (match_operand:HI 2 "h8300_src_operand" "P3>X,P3<X,J,rQi")))]
   "TARGET_H8300SX && h8300_operands_match_p (operands)"
   "@
-   add.w	%T2,%T0
-   sub.w	%G2,%T0
+   add.w	%T2:3,%T0
+   sub.w	%G2:3,%T0
    add.b	%t2,%t0
    add.w	%T2,%T0"
   [(set_attr "length_table" "short_immediate,short_immediate,*,addw")
@@ -1733,6 +1761,13 @@
 ;; ----------------------------------------------------------------------
 ;; AND INSTRUCTIONS
 ;; ----------------------------------------------------------------------
+(define_insn "bclrqi_msx"
+  [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
+        (and:QI (match_operand:QI 1 "bit_memory_operand" "%0")
+                (match_operand 2 "const_int_operand" "n")))]
+  "TARGET_H8300SX & single_zero_operand (operands[2], QImode)"
+  "bclr\\t%W2,%0"
+  [(set_attr "length" "8")])
 
 (define_insn "*andqi3_2"
   [(set (match_operand:QI 0 "bit_operand" "=rQ,r")
@@ -1838,6 +1873,14 @@
 ;; OR INSTRUCTIONS
 ;; ----------------------------------------------------------------------
 
+(define_insn "bsetqi_msx"
+  [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
+        (ior:QI (match_operand:QI 1 "bit_memory_operand" "%0")
+                (match_operand 2 "const_int_operand" "n")))]
+  "TARGET_H8300SX & single_one_operand (operands[2], QImode)"
+  "bset\\t%V2,%0"
+  [(set_attr "length" "8")])
+
 (define_insn "iorqi3_1"
   [(set (match_operand:QI 0 "bit_operand" "=rQ,U")
 	(ior:QI (match_operand:QI 1 "bit_operand" "%0,0")
@@ -1875,6 +1918,13 @@
 ;; ----------------------------------------------------------------------
 ;; XOR INSTRUCTIONS
 ;; ----------------------------------------------------------------------
+(define_insn "bnotqi_msx"
+  [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
+        (xor:QI (match_operand:QI 1 "bit_memory_operand" "%0")
+                (match_operand 2 "const_int_operand" "n")))]
+  "TARGET_H8300SX & single_one_operand (operands[2], QImode)"
+  "bnot\\t%V2,%0"
+  [(set_attr "length" "8")])
 
 (define_insn "xorqi3_1"
   [(set (match_operand:QI 0 "bit_operand" "=r,U")
@@ -3162,7 +3212,7 @@
 				 (match_operand:HI 3 "const_int_operand" "n"))
 			 (const_int 1)
 			 (match_operand:HI 2 "const_int_operand" "n")))]
-  "TARGET_H8300
+  "(TARGET_H8300 || TARGET_H8300SX)
    && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
   "sub.w	%0,%0\;bild	%Z2,%Y1\;bst	#0,%X0"
   [(set_attr "length" "8")])
@@ -6117,3 +6167,31 @@
    && !reg_overlap_mentioned_p (operands[0], operands[2])"
   [(set (match_dup 2)
 	(match_dup 1))])
+
+(define_peephole
+  [(set (pc)
+	(if_then_else (match_operator 1 "eqne_operator"
+				      [(cc0) (const_int 0)])
+		      (label_ref (match_operand 0 "" ""))
+		      (pc)))
+  (set (match_operand:QI 2 "bit_memory_operand" "=WU")
+        (ior:QI (match_operand:QI 3 "bit_memory_operand" "%2")
+                (match_operand 4 "const_int_operand" "n")))]
+  "TARGET_H8300SX && single_one_operand (operands[4], QImode)"
+  "bset/%k1\t%V4,%2
+   \\tb%j1\t%l0"
+  )
+  
+(define_peephole
+  [(set (pc)
+	(if_then_else (match_operator 1 "eqne_operator"
+				      [(cc0) (const_int 0)])
+		      (label_ref (match_operand 0 "" ""))
+		      (pc)))
+  (set (match_operand:QI 2 "bit_memory_operand" "=WU")
+        (and:QI (match_operand:QI 3 "bit_memory_operand" "%2")
+                (match_operand 4 "const_int_operand" "n")))]
+  "TARGET_H8300SX && single_zero_operand (operands[4], QImode)"
+  "bclr/%k1\t%W4,%2
+   \\tb%j1\t%l0"
+  )
