This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] h8300.md: Add a new peephole2.


Hi,

Attached is a patch to add a new peephole2.

Often, people do

  "if ((A & CST1) == CST2)".

If A is in SImode and dies, and CST is narrow enough, we can convert
this to

  " if (((unsigned char) A & CST1) == CST2)"

In terms of assembly code

	and.l	#9,er2  ; andsi 6 bytes
 	xor	#9,r2l  ; xorsi 2 bytes
	mov.l	er2,er2 ; movsi 2 bytes
 	bne	.L2

becomes

	and	#9,r2l ; andqi 2 bytes
 	xor	#9,r2l ; xorqi 2 bytes
 	bne	.L2

Saving 6 bytes.  The patch implements this transformation as a
peephole2.

Tested on h8300 port.  Committed.

Kazu Hirata

2003-02-21  Kazu Hirata  <kazu at cs dot umass dot edu>

	* config/h8300/h8300.md (a peephole2): New.

Index: h8300.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.md,v
retrieving revision 1.173
diff -u -r1.173 h8300.md
--- h8300.md	20 Feb 2003 23:11:35 -0000	1.173
+++ h8300.md	21 Feb 2003 13:06:25 -0000
@@ -3847,3 +3847,35 @@
 		      (pc)))]
   "operands[4] = gen_rtx_REG (HImode, REGNO (operands[0]));
    operands[5] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), HImode));")
+
+(define_peephole2
+  [(set (match_operand:SI 0 "register_operand" "")
+	(and:SI (match_dup 0)
+		(match_operand:SI 1 "const_int_qi_operand" "")))
+   (set (match_dup 0)
+	(xor:SI (match_dup 0)
+		(match_operand:SI 2 "const_int_qi_operand" "")))
+   (set (cc0)
+	(match_dup 0))
+   (set (pc)
+	(if_then_else (match_operator 4 "eqne_operator"
+			[(cc0) (const_int 0)])
+		      (label_ref (match_operand 3 "" ""))
+		      (pc)))]
+  "peep2_reg_dead_p (3, operands[0])
+   && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0"
+  [(set (match_dup 5)
+	(and:QI (match_dup 5)
+		(match_dup 6)))
+   (set (match_dup 5)
+	(xor:QI (match_dup 5)
+		(match_dup 7)))
+   (set (cc0)
+	(match_dup 5))
+   (set (pc)
+	(if_then_else (match_op_dup 4 [(cc0) (const_int 0)])
+		      (label_ref (match_dup 3))
+		      (pc)))]
+  "operands[5] = gen_rtx_REG (QImode, REGNO (operands[0]));
+   operands[6] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));
+   operands[7] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), QImode));")


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]