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

Kazu Hirata kazu@cs.umass.edu
Wed Feb 12 23:33:00 GMT 2003


Hi,

Attached is a patch to add a new peephole2.  The new peephole2
transforms

	cmp.l	#-1,er1 ; compare -1 and er1
 	beq	.L7     ; branch if equal

into

	mov.l	er1,er2 ; copy er1 to er2
	inc.l	#1,er2  ; increment er2
 	beq	.L7     ; branch if equal

when er1 does not die, but a scratch register, er2 in this case, is
available.  This transformation saves 2 bytes.  The constants are
limited to -2, -1, 1, and 2.

Tested on h8300 port.  Committed.

Kazu Hirata

2003-02-12  Kazu Hirata  <kazu@cs.umass.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.163
diff -u -r1.163 h8300.md
--- h8300.md	12 Feb 2003 14:10:21 -0000	1.163
+++ h8300.md	12 Feb 2003 23:07:15 -0000
@@ -3561,6 +3561,36 @@
 		  gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx) :
 		  gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx));")
 
+;; For constants like -1, -2, 1, 2, it is still cheaper to make a copy
+;; of the register being tested, do the subtraction on the copy, and
+;; then test the copy.  We avoid this transformation if we see more
+;; than one copy of the same compare insn.
+
+(define_peephole2
+  [(match_scratch:SI 4 "r")
+   (set (cc0)
+	(compare:SI (match_operand:SI 0 "register_operand" "")
+		    (match_operand:SI 1 "incdec_operand" "")))
+   (set (pc)
+	(if_then_else (match_operator 3 "eqne_operator"
+			[(cc0) (const_int 0)])
+		      (label_ref (match_operand 2 "" ""))
+		      (pc)))]
+  "(TARGET_H8300H || TARGET_H8300S)
+   && !peep2_reg_dead_p (1, operands[0])
+   && !rtx_equal_p (PATTERN (insn),
+		    PATTERN (next_nonnote_insn (next_nonnote_insn (insn))))"
+  [(set (cc0)
+	(match_dup 0))
+   (set (pc)
+	(if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
+		      (label_ref (match_dup 2))
+		      (pc)))]
+  "emit_move_insn (operands[4], operands[0]);
+   operands[0] = operands[4];
+   operands[1] = GEN_INT (- INTVAL (operands[1]));
+   split_adds_subs (SImode, operands, 1);")
+
 ;; Narrow the mode of testing if possible.
 
 (define_peephole2



More information about the Gcc-patches mailing list