This is the mail archive of the gcc@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]

Re: Optimizing if (foo==1 || foo==3 || foo==7 || etc...) ???


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


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