This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: make genattrtab generate smaller code
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: matz at suse dot de
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 5 Sep 2003 17:39:40 -0400 (EDT)
- Subject: Re: make genattrtab generate smaller code
- References: <Pine.LNX.4.44.0309052057230.13736-100000@wotan.suse.de>
> This patch moves all the get_attr_xxx calls inside the if()s to the
> front of the function by caching the results, in order to save several
> hundred function calls, i.e. like:
>
> enum attr_x get_attr_lala (rtx insn) {
> enum attr_memory attr_memory = get_attr_memory(insn);
> switch (recog_memoized(insn)) {
> case xxx:
> if (bla && attr_memory == XXX) {
> } else if (blubb && attr_memory == XXX) {
> } else if (bla2 && attr_memory == YYY) {
> } else {
> }
Cool. I was wondering if we could get GCC to do some of this
automatically by adding the "const" or "pure" function attribute to
get_attr_memory() and like functions in the insn-* generated files.
If so, then GCC should optimize this for us (and in perhaps more cases
than with your patch alone.)
> I also experimented with merging the multiple test on
> which_alternative to use '&', ala
>
> if ((which_alternative == 1) || (which_alternative == 2))
> -->
> if ((1 << which_alternative) & 0x6)
>
> but this didn't result in smaller or faster code.
>
IIRC, not too long ago someone posted a patch to add this optimization
to GCC across the board. I don't recall if it went in or not, nor do
I recall the URL. But it would be nice to have the compiler
automatically do this for us too. :-)
--Kaveh
--
Kaveh R. Ghazi ghazi@caip.rutgers.edu