This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] h8300.md: Add a new peephole.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 10 Jul 2003 02:23:50 -0400 (EDT)
- Subject: [patch] h8300.md: Add a new peephole.
Hi,
Attached is a patch to add a new peephole. The new peephole converts
if (A == -2147483648) goto LABEL;
into
A = (A << 1) | (A >> 30); /* Rotate left by one bit. */
A--;
if (A == 0) goto LABEL;
In terms assembly code:
cmp.l #-2147483648,er2
beq .L2
into
rotl.l #2,er2
dec.l #1,er2
beq .L2
The peephole2 saves 2 bytes. Similar transformations apply for bne
and constant 1073741824.
Tested on h8300 port. Committed.
Kazu Hirata
2003-07-10 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.232
diff -u -r1.232 h8300.md
--- h8300.md 7 Jul 2003 19:19:01 -0000 1.232
+++ h8300.md 10 Jul 2003 04:39:24 -0000
@@ -4120,6 +4120,8 @@
;;
;; dead 0xffffff?? except -1 and -2 eq/ne xor.b and not.l
;; dead 0xffff??ff eq/ne xor.b and not.l
+;; dead 0x40000000 (H8S) eq/ne rotl.l and dec.l
+;; dead 0x80000000 eq/ne rotl.l and dec.l
;;
;; live 1 geu/ltu copy and shar.l
;; live 3 (H8S) geu/ltu copy and shar.l
@@ -4247,6 +4249,34 @@
(label_ref (match_dup 2))
(pc)))]
"operands[4] = GEN_INT (INTVAL (operands[1]) ^ -1);")
+
+(define_peephole2
+ [(set (cc0)
+ (compare (match_operand:SI 0 "register_operand" "")
+ (match_operand:SI 1 "const_int_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])
+ && (INTVAL (operands[1]) == -2147483648
+ || (TARGET_H8300S && INTVAL (operands[1]) == 1073741824))"
+ [(set (match_dup 0)
+ (rotate:SI (match_dup 0)
+ (match_dup 4)))
+ (set (match_dup 0)
+ (unspec:SI [(match_dup 0)
+ (const_int -1)]
+ UNSPEC_INCDEC))
+ (set (cc0)
+ (match_dup 0))
+ (set (pc)
+ (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
+ (label_ref (match_dup 2))
+ (pc)))]
+ "operands[4] = GEN_INT (INTVAL (operands[1]) == -2147483648 ? 1 : 2);")
;; Transform
;;