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.c: Optimize or.l.


Hi,

Attached is a patch to optimize or.l.

"A | 0xffffff00", where A is in SImode, can be done efficiently by
ORing with 0x0000ff00 followed by sign extension.  In terms of
assembly code,

	or.l	#-256,er2

becomes

	or	#255,r2h
	exts.l	er2

shortening the length from 6 bytes to 4 bytes.  This optimization is
profitable for constants of the form 0xffff??00 with the highest bit
of the ?? part set.

Tested on h8300 port.  Committed.

Kazu Hirata

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

	* config/h8300/h8300.c (output_logical_op): Optimize or.l when
	ORing with 0xffff??00 with the highest bit of the ?? part set.
	(compute_logical_op_length): Update.
	(compute_logical_op_cc): Likewise.

Index: h8300.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.c,v
retrieving revision 1.214
diff -u -r1.214 h8300.c
--- h8300.c	19 Feb 2003 12:53:32 -0000	1.214
+++ h8300.c	19 Feb 2003 21:12:39 -0000
@@ -2206,7 +2206,9 @@
 	 using multiple insns.  */
       if ((TARGET_H8300H || TARGET_H8300S)
 	  && w0 != 0 && w1 != 0
-	  && !(lower_half_easy_p && upper_half_easy_p))
+	  && !(lower_half_easy_p && upper_half_easy_p)
+	  && !(code == IOR && w1 == 0xffff
+	       && (w0 & 0x8000) != 0 && lower_half_easy_p))
 	{
 	  sprintf (insn_buf, "%s.l\t%%S2,%%S0", opname);
 	  output_asm_insn (insn_buf, operands);
@@ -2251,6 +2253,13 @@
 			     ? "sub.w\t%e0,%e0" : "not.w\t%e0",
 			     operands);
 	  else if ((TARGET_H8300H || TARGET_H8300S)
+		   && code == IOR
+		   && w1 == 0xffff
+		   && (w0 & 0x8000) != 0)
+	    {
+	      output_asm_insn ("exts.l\t%S0", operands);
+	    }
+	  else if ((TARGET_H8300H || TARGET_H8300S)
 		   && code == AND
 		   && w1 == 0xff00)
 	    {
@@ -2354,7 +2363,9 @@
 	 using multiple insns.  */
       if ((TARGET_H8300H || TARGET_H8300S)
 	  && w0 != 0 && w1 != 0
-	  && !(lower_half_easy_p && upper_half_easy_p))
+	  && !(lower_half_easy_p && upper_half_easy_p)
+	  && !(code == IOR && w1 == 0xffff
+	       && (w0 & 0x8000) != 0 && lower_half_easy_p))
 	{
 	  if (REG_P (operands[2]))
 	    length += 4;
@@ -2395,6 +2406,13 @@
 	      length += 2;
 	    }
 	  else if ((TARGET_H8300H || TARGET_H8300S)
+		   && code == IOR
+		   && w1 == 0xffff
+		   && (w0 & 0x8000) != 0)
+	    {
+	      length += 2;
+	    }
+	  else if ((TARGET_H8300H || TARGET_H8300S)
 		   && code == AND
 		   && w1 == 0xff00)
 	    {
@@ -2475,9 +2493,21 @@
 	 using multiple insns.  */
       if ((TARGET_H8300H || TARGET_H8300S)
 	  && w0 != 0 && w1 != 0
-	  && !(lower_half_easy_p && upper_half_easy_p))
+	  && !(lower_half_easy_p && upper_half_easy_p)
+	  && !(code == IOR && w1 == 0xffff
+	       && (w0 & 0x8000) != 0 && lower_half_easy_p))
 	{
 	  cc = CC_SET_ZNV;
+	}
+      else
+	{
+	  if ((TARGET_H8300H || TARGET_H8300S)
+	      && code == IOR
+	      && w1 == 0xffff
+	      && (w0 & 0x8000) != 0)
+	    {
+	      cc = CC_SET_ZNV;
+	    }
 	}
       break;
     default:


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