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] genrecog.c: Simplify comparisons against small constantsin insn-recog.c.


Hi,

Attached is a patch to simplify comparisons against small constants in
insn-recog.c by replacing

  if (GET_CODE (x3) == CONST_INT
      && XWINT (x3, 0) == 10L
      && ...

with

  if (x3 == const_int_rtx[MAX_SAVED_CONST_INT + (10)]
      && ...

Aside from a code size improvement of 0.2% on cc1, this patch replaces
a pointer chasing with a comparison against a link-time constant.

I understand that we shouldn't use const_int_rtx everywhere, but in
these internal machineries, I hope its use is OK.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-01-28  Kazu Hirata  <kazu@cs.umass.edu>

	* genrecog.c (decision_type): Add DT_const_int.
	(write_cond) [DT_const_int]: Print a comparison against small
	constant.
	(write_node): Simplify comparisons against small constants
	before printing tests.
	
Index: genrecog.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genrecog.c,v
retrieving revision 1.136
diff -u -p -r1.136 genrecog.c
--- genrecog.c	28 Jan 2004 21:07:09 -0000	1.136
+++ genrecog.c	28 Jan 2004 21:20:30 -0000
@@ -90,6 +90,7 @@ struct decision_test
     {
       DT_mode, DT_code, DT_veclen,
       DT_elt_zero_int, DT_elt_one_int, DT_elt_zero_wide, DT_elt_zero_wide_safe,
+      DT_const_int,
       DT_veclen_ge, DT_dup, DT_pred, DT_c_test,
       DT_accept_op, DT_accept_insn
     } type;
@@ -1981,6 +1982,11 @@ write_cond (struct decision_test *p, int
       print_host_wide_int (p->u.intval);
       break;
 
+    case DT_const_int:
+      printf ("x%d == const_int_rtx[MAX_SAVED_CONST_INT + (%d)]",
+	      depth, (int) p->u.intval);
+      break;
+
     case DT_veclen_ge:
       printf ("XVECLEN (x%d, 0) >= %d", depth, p->u.veclen);
       break;
@@ -2142,6 +2148,23 @@ write_node (struct decision *p, int dept
 {
   struct decision_test *test, *last_test;
   int uncond;
+
+  /* Scan the tests and simplify comparisons against small
+     constants.  */
+  for (test = p->tests; test; test = test->next)
+    {
+      if (test->type == DT_code
+	  && test->u.code == CONST_INT
+	  && test->next
+	  && test->next->type == DT_elt_zero_wide_safe
+	  && -MAX_SAVED_CONST_INT <= test->next->u.intval
+	  && test->next->u.intval <= MAX_SAVED_CONST_INT)
+	{
+	  test->type = DT_const_int;
+	  test->u.intval = test->next->u.intval;
+	  test->next = test->next->next;
+	}
+    }
 
   last_test = test = p->tests;
   uncond = is_unconditional (test, subroutine_type);


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