This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] cse.c: Speed up cse_reg_info maintanance - Part 3
- From: Richard Earnshaw <rearnsha at gcc dot gnu dot org>
- To: Kazu Hirata <kazu at cs dot umass dot edu>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 02 Feb 2005 10:14:00 +0000
- Subject: Re: [patch] cse.c: Speed up cse_reg_info maintanance - Part 3
- Organization: GNU
- References: <20050201.181240.78705384.kazu@cs.umass.edu>
On Tue, 2005-02-01 at 23:12, Kazu Hirata wrote:
> Hi,
>
> Attached is a patch to speed up cse_reg_info maintainance by
> dramatically simplifying the memory allocation.
>
> The patch replaces this complicated use of xrealloc with xmalloc.
>
> Here is a timing in seconds for ./cc1 -quiet -O2 -o /dev/null.
>
> original patched diff%
> c-common.i 18.334 18.231 -0.561%
> combine.i 17.475 17.425 -0.286%
> fold-const.i 38.048 37.938 -0.289%
> reload.i 13.497 13.444 -0.392%
> reload1.i 14.258 14.229 -0.203%
> cc1-i files 212.457 212.256 -0.094%
>
> cc1-i files were compiled only once.
>
> To my surprise, it's better to free memory when we are not using it,
> that is, between passes of cse_main. I thought it would be a good
> idea to keep it if similar amount of memory is used over and over.
> Maybe other passes can use the same memory locations for other
> purposes and thereby improve locality!? xrealloc may have been
> somewhat expensive.
It seems to me, that if it's just the cost of xrealloc copying the dead
memory that's slowing things down, then the following would probably be
a better patch. This should also go some way to address Mike's concerns
since we now avoid mallocs whenever the table hasn't grown.
I guess there are some versions of realloc that can grow an existing
chunk of memory under some circumstances and that this can be cheaper
than mallocing a new block, but it's likely that the copy will always
dominate the common case.
This is untested, and posted purely by way of suggestion of an
alternative approach.
R.
Index: cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.339
diff -p -r1.339 cse.c
*** cse.c 1 Feb 2005 00:41:56 -0000 1.339
--- cse.c 2 Feb 2005 10:10:18 -0000
*************** init_cse_reg_info (unsigned int nregs)
*** 861,870 ****
new_size = nregs;
}
! /* Reallocate the table with NEW_SIZE entries. */
! cse_reg_info_table = xrealloc (cse_reg_info_table,
! (sizeof (struct cse_reg_info)
! * new_size));
cse_reg_info_table_size = new_size;
}
--- 861,874 ----
new_size = nregs;
}
! /* Reallocate the table with NEW_SIZE entries. Don't use xrealloc,
! since we don't need to copy the old data. */
! if (cse_reg_info_table)
! free (cse_reg_info_table);
!
! cse_reg_info_table = xmalloc (cse_reg_info_table,
! (sizeof (struct cse_reg_info)
! * new_size));
cse_reg_info_table_size = new_size;
}