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]

Simple speedup patches


Here is patch which should speed up gcc (some of them will only be seen with checking turned on).
I used Shikari, woops I mean Shark, from Apple's CHUD tools to find these.
This patch might give somewhere around 1 percent win, I have not timed it and I do not have the machine time to time it.
The patch removes some redundant checks, mostly with checking on, and moves code around. It removes invariant loads from some loops, as shown by Shark, and moves one case statement out of a switch because it is the case statement that occurs the most (there should be a way for the back-end to do this with the profiling data).


Thanks,
Andrew Pinski

ChangeLog:

2003-04-22 Andrew Pinski <pinskia at physics dot uc dot edu>

	* alias.c (rtx_equal_for_memref_p): Move equality check
	before the check for zero, remove redundant check for
	double zero. (find_base_term): Move case `REG' out of the switch.
	* cfgrtl.c (verify_flow_info): Remove redundant INSN_UID.
	Remove invariant load in the loop over instructions in the basic
	block.
	* gcse.c (trim_ld_motion_mems): Remove invariant load for
	ptr->pattern. (compute_store_table): Remove invariant load for
	INSN_UID (insn). (find_loads): Remove redundant checks for
	GET_CODE (x).
	* loop.c (loop_regs_scan): Remove invariant load for regs->num.
	* rtlanal.c (reg_mentioned_p): Remove redundant checks for
	GET_CODE (in). (for_each_rtx): Remove redundant checks for
	GET_CODE (*x).

cp/ChangeLog:

2003-04-22	Andrew Pinski <pinskia at physics dot uc dot edu>
	* typeck.c (comptypes): Move when the AND for strict after the
	simple equality checks.

Patch:

Index: alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/alias.c,v
retrieving revision 1.191
diff -u -d -b -w -u -p -r1.191 alias.c
--- alias.c	5 Apr 2003 15:57:40 -0000	1.191
+++ alias.c	22 Apr 2003 22:33:56 -0000
@@ -1131,13 +1131,12 @@ rtx_equal_for_memref_p (x, y)
   enum rtx_code code;
   const char *fmt;

-  if (x == 0 && y == 0)
+  if (x == y)
     return 1;
+
   if (x == 0 || y == 0)
     return 0;

-  if (x == y)
-    return 1;

   code = GET_CODE (x);
   /* Rtx's of different codes cannot be equal.  */
@@ -1304,17 +1303,20 @@ find_base_term (x)
 {
   cselib_val *val;
   struct elt_loc_list *l;
+  enum rtx_code code;

 #if defined (FIND_BASE_TERM)
   /* Try machine-dependent ways to find the base term.  */
   x = FIND_BASE_TERM (x);
 #endif
+  code = GET_CODE (x);

-  switch (GET_CODE (x))
-    {
-    case REG:
+  if (code == REG)
       return REG_BASE_VALUE (x);

+  switch (code)
+    {
+
     case TRUNCATE:
       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (Pmode))
 	return 0;
Index: cfgrtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgrtl.c,v
retrieving revision 1.75
diff -u -d -b -w -u -p -r1.75 cfgrtl.c
--- cfgrtl.c	18 Apr 2003 22:04:12 -0000	1.75
+++ cfgrtl.c	22 Apr 2003 22:33:59 -0000
@@ -1797,17 +1797,19 @@ verify_flow_info ()
 	 to verify the head is in the RTL chain.  */
       for (; x != NULL_RTX; x = PREV_INSN (x))
 	{
+          int uid = INSN_UID (x);
+
 	  /* While walking over the insn chain, verify insns appear
 	     in only one basic block and initialize the BB_INFO array
 	     used by other passes.  */
-	  if (bb_info[INSN_UID (x)] != NULL)
+	  if (bb_info[uid] != NULL)
 	    {
 	      error ("insn %d is in multiple basic blocks (%d and %d)",
-		     INSN_UID (x), bb->index, bb_info[INSN_UID (x)]->index);
+		     uid, bb->index, bb_info[uid]->index);
 	      err = 1;
 	    }

-	  bb_info[INSN_UID (x)] = bb;
+	  bb_info[uid] = bb;

if (x == head)
break;
@@ -1828,6 +1830,7 @@ verify_flow_info ()
int n_fallthru = 0, n_eh = 0, n_call = 0, n_abnormal = 0, n_branch = 0;
edge e;
rtx note;
+ rtx bbendnext;


       if (INSN_P (bb->end)
 	  && (note = find_reg_note (bb->end, REG_BR_PROB, NULL_RTX))
@@ -2013,7 +2016,8 @@ verify_flow_info ()
 	  edge_checksum[e->dest->index + 2] -= (size_t) e;
 	}

-      for (x = bb->head; x != NEXT_INSN (bb->end); x = NEXT_INSN (x))
+      bbendnext = NEXT_INSN (bb->end);
+      for (x = bb->head; x != bbendnext; x = NEXT_INSN (x))
 	if (BLOCK_FOR_INSN (x) != bb)
 	  {
 	    debug_rtx (x);
Index: gcse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcse.c,v
retrieving revision 1.247
diff -u -d -b -w -u -p -r1.247 gcse.c
--- gcse.c	18 Apr 2003 01:29:19 -0000	1.247
+++ gcse.c	22 Apr 2003 22:34:08 -0000
@@ -6859,6 +6859,7 @@ trim_ld_motion_mems ()
       if (!del)
 	{
 	  unsigned int i;
+          rtx ptrpattern = ptr->pattern;

 	  del = 1;
 	  /* Delete if we cannot find this mem in the expression list.  */
@@ -6867,7 +6868,7 @@ trim_ld_motion_mems ()
 	      for (expr = expr_hash_table.table[i];
 		   expr != NULL;
 		   expr = expr->next_same_hash)
-		if (expr_equiv_p (expr->expr, ptr->pattern))
+		if (expr_equiv_p (expr->expr, ptrpattern))
 		  {
 		    del = 0;
 		    break;
@@ -7283,6 +7284,7 @@ compute_store_table ()
 	   insn != NEXT_INSN (bb->end);
 	   insn = NEXT_INSN (insn))
 	{
+          int uid;
 	  if (! INSN_P (insn))
 	    continue;

@@ -7306,10 +7308,10 @@ compute_store_table ()

 	  /* Now that we've marked regs, look for stores.  */
 	  find_moveable_store (insn, already_set, last_set_in);
-
+          uid = INSN_UID (insn);
 	  /* Unmark regs that are no longer set.  */
 	  for (regno = 0; regno < max_gcse_regno; regno++)
-	    if (last_set_in[regno] == INSN_UID (insn))
+	    if (last_set_in[regno] == uid)
 	      last_set_in[regno] = 0;
 	}

@@ -7371,24 +7373,31 @@ find_loads (x, store_pattern)
 {
   const char * fmt;
   int i, j;
+  enum rtx_code code;
   int ret = false;

   if (!x)
     return false;

-  if (GET_CODE (x) == SET)
+  code = GET_CODE (x);
+
+  if (code == SET)
+    {
     x = SET_SRC (x);
+      code = GET_CODE (x);
+    }

-  if (GET_CODE (x) == MEM)
+  if (code == MEM)
     {
       if (load_kills_store (x, store_pattern))
 	return true;
     }

+
   /* Recursively process the insn.  */
-  fmt = GET_RTX_FORMAT (GET_CODE (x));
+  fmt = GET_RTX_FORMAT (code);

-  for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0 && !ret; i--)
+  for (i = GET_RTX_LENGTH (code) - 1; i >= 0 && !ret; i--)
     {
       if (fmt[i] == 'e')
 	ret |= find_loads (XEXP (x, i), store_pattern);
Index: loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.452
diff -u -d -b -w -u -p -r1.452 loop.c
--- loop.c	3 Apr 2003 19:20:04 -0000	1.452
+++ loop.c	22 Apr 2003 22:34:12 -0000
@@ -590,7 +590,6 @@ next_insn_in_loop (loop, insn)
 }

/* Optimize one loop described by LOOP. */
-
/* ??? Could also move memory writes out of loops if the destination address
is invariant, the source is invariant, the memory write is not volatile,
and if we can prove that no read inside the loop can read this address
@@ -9700,7 +9699,7 @@ loop_regs_scan (loop, extra_size)
basic block. In that case, it is the insn that last set reg n. */
rtx *last_set;
rtx insn;
- int i;
+ int i, regsnum;


   old_nregs = regs->num;
   regs->num = max_reg_num ();
@@ -9796,9 +9795,9 @@ loop_regs_scan (loop, extra_size)
     if (GET_MODE_CLASS (GET_MODE (regno_reg_rtx[i])) == MODE_CC)
       regs->array[i].may_not_optimize = 1;
 #endif
-
+  regsnum = regs->num;
   /* Set regs->array[I].n_times_set for the new registers.  */
-  for (i = old_nregs; i < regs->num; i++)
+  for (i = old_nregs; i < regsnum; i++)
     regs->array[i].n_times_set = regs->array[i].set_in_loop;

   free (last_set);
Index: rtlanal.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtlanal.c,v
retrieving revision 1.155
diff -u -d -b -w -u -p -r1.155 rtlanal.c
--- rtlanal.c	19 Apr 2003 12:57:36 -0000	1.155
+++ rtlanal.c	22 Apr 2003 22:34:16 -0000
@@ -736,11 +736,11 @@ reg_mentioned_p (reg, in)
   if (reg == in)
     return 1;

-  if (GET_CODE (in) == LABEL_REF)
-    return reg == XEXP (in, 0);
-
   code = GET_CODE (in);

+  if (code == LABEL_REF)
+    return reg == XEXP (in, 0);
+
   switch (code)
     {
       /* Compare registers by number.  */
@@ -3041,6 +3041,7 @@ for_each_rtx (x, f, data)
   int length;
   const char *format;
   int i;
+  enum rtx_code code;

   /* Call F on X.  */
   result = (*f) (x, data);
@@ -3055,8 +3056,10 @@ for_each_rtx (x, f, data)
     /* There are no sub-expressions.  */
     return 0;

-  length = GET_RTX_LENGTH (GET_CODE (*x));
-  format = GET_RTX_FORMAT (GET_CODE (*x));
+  code = GET_CODE (*x);
+
+  length = GET_RTX_LENGTH (code);
+  format = GET_RTX_FORMAT (code);

   for (i = 0; i < length; ++i)
     {
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.457
diff -u -d -b -w -u -p -r1.457 typeck.c
--- cp/typeck.c	22 Apr 2003 05:44:11 -0000	1.457
+++ cp/typeck.c	22 Apr 2003 22:34:30 -0000
@@ -899,15 +899,6 @@ comptypes (t1, t2, strict)
   int attrval, val;
   int orig_strict = strict;

-  /* The special exemption for redeclaring array types without an
-     array bound only applies at the top level:
-
-       extern int (*i)[];
-       int (*i)[8];
-
-     is invalid, for example.  */
-  strict &= ~COMPARE_REDECLARATION;
-
   /* Suppress errors caused by previously reported errors */
   if (t1 == t2)
     return 1;
@@ -960,6 +951,16 @@ comptypes (t1, t2, strict)
   /* Qualifiers must match.  */
   if (cp_type_quals (t1) != cp_type_quals (t2))
     return 0;
+
+  /* The special exemption for redeclaring array types without an
+    array bound only applies at the top level:
+
+    extern int (*i)[];
+  int (*i)[8];
+
+  is invalid, for example.  */
+  strict &= ~COMPARE_REDECLARATION;
+
   if (strict == COMPARE_STRICT
       && TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
     return 0;

Attachment: mycurrent.patch.20030422
Description: Binary data


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