--- rx.md.bitmem	2012-06-27 22:05:19.000000000 +0900
+++ rx.md	2012-12-20 22:17:41.745650509 +0900
@@ -2622,3 +2796,194 @@
   ""
   ""
 )
+
+;
+;	mov.B	[reg1], reg0
+;	or	#x, reg0
+;	mov.B	reg0, [reg1]
+;
+;	bset	#n, [reg1].B
+;
+(define_peephole2
+  [
+   (set (match_operand:SI 0 "register_operand" "")
+        (sign_extend:SI (match_operand:QI 1 "rx_restricted_mem_operand" "")))
+   (parallel[
+        (set (match_dup 0)
+             (ior:SI (match_dup 0)
+                     (match_operand:QI 2 "const_int_operand" "")))
+        (clobber (reg:CC CC_REG))])
+   (set (match_dup 1)
+        (match_operand:QI 3 "register_operand" ""))
+  ]
+  "!TARGET_BIG_ENDIAN_DATA
+   && REGNO (operands[0]) == REGNO (operands[3])
+   && satisfies_constraint_Q (operands[1])
+   && exact_log2 (INTVAL (operands[2]) & 0xff) >= 0
+   && exact_log2 (INTVAL (operands[2]) & 0xff) <= 7
+   && peep2_reg_dead_p (3, operands[0])
+  "
+  [
+    (set (match_dup 1)
+         (subreg:QI (ior:SI (subreg:SI (match_dup 1) 0)
+                 (match_dup 2)) 0))
+  ]
+  "
+  "
+)
+
+(define_peephole2
+  [
+   (set (match_operand:SI 0 "register_operand" "")
+        (sign_extend:SI (match_operand:QI 1 "rx_restricted_mem_operand" "")))
+   (parallel[
+        (set (match_dup 0)
+             (ior:SI (match_dup 0)
+                     (match_operand:QI 2 "const_int_operand" "")))
+        (clobber (reg:CC CC_REG))])
+   (set (match_dup 1)
+        (match_operand:QI 3 "register_operand" ""))
+  ]
+  "TARGET_BIG_ENDIAN_DATA
+   && REGNO (operands[0]) == REGNO (operands[3])
+   && satisfies_constraint_Q (operands[1])
+   && exact_log2 (INTVAL (operands[2]) & 0xff) >= 0
+   && exact_log2 (INTVAL (operands[2]) & 0xff) <= 7
+   && peep2_reg_dead_p (3, operands[0])
+  "
+  [
+    (set (match_dup 1)
+         (subreg:QI (ior:SI (subreg:SI (match_dup 1) 0)
+                 (match_dup 2)) 3))
+  ]
+  "
+  "
+)
+
+;
+;	mov.B	[reg1], reg0
+;	xor	#x, reg0
+;	mov.B	reg0, [reg1]
+;
+;	bnot	#n, [reg1].B
+;
+(define_peephole2
+  [
+   (set (match_operand:SI 0 "register_operand" "")
+        (sign_extend:SI (match_operand:QI 1 "rx_restricted_mem_operand" "")))
+   (parallel[
+        (set (match_dup 0)
+             (xor:SI (match_dup 0)
+                     (match_operand:QI 2 "const_int_operand" "")))
+        (clobber (reg:CC CC_REG))])
+   (set (match_dup 1)
+        (match_operand:QI 3 "register_operand" ""))
+  ]
+  "!TARGET_BIG_ENDIAN_DATA
+   && REGNO (operands[0]) == REGNO (operands[3])
+   && satisfies_constraint_Q (operands[1])
+   && exact_log2 (INTVAL (operands[2]) & 0xff) >= 0
+   && exact_log2 (INTVAL (operands[2]) & 0xff) <= 7
+   && peep2_reg_dead_p (3, operands[0])
+  "
+  [
+    (set (match_dup 1)
+         (subreg:QI (xor:SI (subreg:SI (match_dup 1) 0)
+                 (match_dup 2)) 0))
+  ]
+  "
+  "
+)
+
+(define_peephole2
+  [
+   (set (match_operand:SI 0 "register_operand" "")
+        (sign_extend:SI (match_operand:QI 1 "rx_restricted_mem_operand" "")))
+   (parallel[
+        (set (match_dup 0)
+             (xor:SI (match_dup 0)
+                     (match_operand:QI 2 "const_int_operand" "")))
+        (clobber (reg:CC CC_REG))])
+   (set (match_dup 1)
+        (match_operand:QI 3 "register_operand" ""))
+  ]
+  "TARGET_BIG_ENDIAN_DATA
+   && REGNO (operands[0]) == REGNO (operands[3])
+   && satisfies_constraint_Q (operands[1])
+   && exact_log2 (INTVAL (operands[2]) & 0xff) >= 0
+   && exact_log2 (INTVAL (operands[2]) & 0xff) <= 7
+   && peep2_reg_dead_p (3, operands[0])
+  "
+  [
+    (set (match_dup 1)
+         (subreg:QI (xor:SI (subreg:SI (match_dup 1) 0)
+                 (match_dup 2)) 3))
+  ]
+  "
+  "
+)
+
+;
+;	mov.B	[reg1], reg0
+;	and	#x, reg0
+;	mov.B	reg0, [reg1]
+;
+;	bclr	#n, [reg1].B
+;
+(define_peephole2
+  [
+   (set (match_operand:SI 0 "register_operand" "")
+        (sign_extend:SI (match_operand:QI 1 "rx_restricted_mem_operand" "")))
+   (parallel[
+        (set (match_dup 0)
+             (and:SI (match_dup 0)
+                     (match_operand 2 "const_int_operand" "")))
+        (clobber (reg:CC CC_REG))])
+   (set (match_dup 1)
+        (match_operand:QI 3 "register_operand" ""))
+  ]
+  "!TARGET_BIG_ENDIAN_DATA
+   && REGNO (operands[0]) == REGNO (operands[3])
+   && satisfies_constraint_Q (operands[1])
+   && exact_log2 (~INTVAL (operands[2]) & 0xff) >= 0
+   && exact_log2 (~INTVAL (operands[2]) & 0xff) <= 7
+   && peep2_reg_dead_p (3, operands[0])
+  "
+  [
+    (set (match_dup 1)
+         (subreg:QI (and:SI (subreg:SI (match_dup 1) 0)
+                 (match_dup 2)) 0))
+  ]
+  "
+  "
+)
+
+(define_peephole2
+  [
+   (set (match_operand:SI 0 "register_operand" "")
+        (sign_extend:SI (match_operand:QI 1 "rx_restricted_mem_operand" "")))
+   (parallel[
+        (set (match_dup 0)
+             (and:SI (match_dup 0)
+                     (match_operand 2 "const_int_operand" "")))
+        (clobber (reg:CC CC_REG))])
+   (set (match_dup 1)
+        (match_operand:QI 3 "register_operand" ""))
+  ]
+  "TARGET_BIG_ENDIAN_DATA
+   && REGNO (operands[0]) == REGNO (operands[3])
+   && satisfies_constraint_Q (operands[1])
+   && exact_log2 (~INTVAL (operands[2]) & 0xff) >= 0
+   && exact_log2 (~INTVAL (operands[2]) & 0xff) <= 7
+   && peep2_reg_dead_p (3, operands[0])
+  "
+  [
+    (set (match_dup 1)
+         (subreg:QI (and:SI (subreg:SI (match_dup 1) 0)
+                 (match_dup 2)) 3))
+  ]
+  "
+  "
+)
+
+
