This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Optimizing if (foo==1 || foo==3 || foo==7 || etc...) ???
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 22 Jan 2004 12:39:46 +0100
- Subject: Re: Optimizing if (foo==1 || foo==3 || foo==7 || etc...) ???
- References: <200401220241.i0M2fINb021057@caip.rutgers.edu>
Hello,
> I was wondering about the optimization where you take
>
> if (foo==1 || foo==3 || foo==7 || etc...)
>
> and turn it into:
>
> if ((1 << foo) & N)
>
> I thought I saw a post from like a year ago adding this optimization
> to GCC but I don't know whether it went in. I think this would be
> useful in making GCC itself faster since we do a lot of this type of
> construct in the insn- files testing the variable `which_alternative'.
at least in insn-attrtab.c we already produce the set membership queries
for which_alternative in the (1 << which_alternative) & set form
directly. I have introduced this mostly to speed up genattrtab; IIRC
it did not have any impacts on the speed of compilation.
Zdenek