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 6 new peephole2 patterns.


Hi,

Attached is a patch to add 6 new peephole2 patterns.

In certain cases, an LSHIFTRT followed by AND can be swapped to
generate a better sequence.  For example, "(a >> 3) & 31" can be
converted to "(a & 255) >> 3", where ANDing with 255 is cheaper than
ANDing with 31.  The same applies to ASHIFT.

The patch implements the above optimization as peepholes.

Tested on h8300 port.  Committed.

Kazu Hirata

2002-11-28  Kazu Hirata  <kazu@cs.umass.edu>

	* config/h8300/h8300.md (6 new peephole2 patterns): New.

Index: h8300.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.md,v
retrieving revision 1.110
diff -u -r1.110 h8300.md
--- h8300.md	26 Nov 2002 02:08:49 -0000	1.110
+++ h8300.md	28 Nov 2002 17:46:56 -0000
@@ -2330,3 +2330,127 @@
 		      (label_ref (match_dup 1))
 		      (pc)))]
   "")
+
+;; -----------------------------------------------------------------
+;; PEEPHOLE PATTERNS
+;; -----------------------------------------------------------------
+
+(define_peephole2
+  [(parallel
+     [(set (match_operand:HI 0 "register_operand" "")
+	   (lshiftrt:HI (match_dup 0)
+			(match_operand:HI 1 "const_int_operand" "")))
+      (clobber (match_operand:HI 2 "" ""))])
+   (set (match_dup 0)
+	(and:HI (match_dup 0)
+		(match_operand:HI 3 "const_int_operand" "")))]
+  "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
+  [(set (match_dup 0)
+	(and:HI (match_dup 0)
+		(const_int 255)))
+   (parallel
+     [(set (match_dup 0)
+	   (lshiftrt:HI (match_dup 0)
+			(match_dup 1)))
+      (clobber (match_dup 2))])]
+  "")
+
+(define_peephole2
+  [(parallel
+     [(set (match_operand:HI 0 "register_operand" "")
+	   (ashift:HI (match_dup 0)
+		      (match_operand:HI 1 "const_int_operand" "")))
+      (clobber (match_operand:HI 2 "" ""))])
+   (set (match_dup 0)
+	(and:HI (match_dup 0)
+		(match_operand:HI 3 "const_int_operand" "")))]
+  "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
+  [(set (match_dup 0)
+	(and:HI (match_dup 0)
+		(const_int 255)))
+   (parallel
+     [(set (match_dup 0)
+	   (ashift:HI (match_dup 0)
+		      (match_dup 1)))
+      (clobber (match_dup 2))])]
+  "")
+
+(define_peephole2
+  [(parallel
+     [(set (match_operand:SI 0 "register_operand" "")
+	   (lshiftrt:SI (match_dup 0)
+			(match_operand:SI 1 "const_int_operand" "")))
+      (clobber (match_operand:SI 2 "" ""))])
+   (set (match_dup 0)
+	(and:SI (match_dup 0)
+		(match_operand:SI 3 "const_int_operand" "")))]
+  "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
+  [(set (match_dup 0)
+	(and:SI (match_dup 0)
+		(const_int 255)))
+   (parallel
+     [(set (match_dup 0)
+	   (lshiftrt:SI (match_dup 0)
+			(match_dup 1)))
+      (clobber (match_dup 2))])]
+  "")
+
+(define_peephole2
+  [(parallel
+     [(set (match_operand:SI 0 "register_operand" "")
+	   (ashift:SI (match_dup 0)
+		      (match_operand:SI 1 "const_int_operand" "")))
+      (clobber (match_operand:SI 2 "" ""))])
+   (set (match_dup 0)
+	(and:SI (match_dup 0)
+		(match_operand:SI 3 "const_int_operand" "")))]
+  "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
+  [(set (match_dup 0)
+	(and:SI (match_dup 0)
+		(const_int 255)))
+   (parallel
+     [(set (match_dup 0)
+	   (ashift:SI (match_dup 0)
+		      (match_dup 1)))
+      (clobber (match_dup 2))])]
+  "")
+
+(define_peephole2
+  [(parallel
+     [(set (match_operand:SI 0 "register_operand" "")
+	   (lshiftrt:SI (match_dup 0)
+			(match_operand:SI 1 "const_int_operand" "")))
+      (clobber (match_operand:SI 2 "" ""))])
+   (set (match_dup 0)
+	(and:SI (match_dup 0)
+		(match_operand:SI 3 "const_int_operand" "")))]
+  "INTVAL (operands[3]) == (65535 >> INTVAL (operands[1]))"
+  [(set (match_dup 0)
+	(and:SI (match_dup 0)
+		(const_int 65535)))
+   (parallel
+     [(set (match_dup 0)
+	   (lshiftrt:SI (match_dup 0)
+			(match_dup 1)))
+      (clobber (match_dup 2))])]
+  "")
+
+(define_peephole2
+  [(parallel
+     [(set (match_operand:SI 0 "register_operand" "")
+	   (ashift:SI (match_dup 0)
+		      (match_operand:SI 1 "const_int_operand" "")))
+      (clobber (match_operand:SI 2 "" ""))])
+   (set (match_dup 0)
+	(and:SI (match_dup 0)
+		(match_operand:SI 3 "const_int_operand" "")))]
+  "INTVAL (operands[3]) == (65535 << INTVAL (operands[1]))"
+  [(set (match_dup 0)
+	(and:SI (match_dup 0)
+		(const_int 65535)))
+   (parallel
+     [(set (match_dup 0)
+	   (ashift:SI (match_dup 0)
+		      (match_dup 1)))
+      (clobber (match_dup 2))])]
+  "")


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