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: Kazu Hirata <kazu at cs dot umass dot edu>
- To: ghazi at caip dot rutgers dot edu
- Cc: gcc at gcc dot gnu dot org, roger at eyesopen dot com
- Date: Wed, 21 Jan 2004 22:15:37 -0500 (EST)
- Subject: Re: Optimizing if (foo==1 || foo==3 || foo==7 || etc...) ???
- References: <200401220241.i0M2fINb021057@caip.rutgers.edu>
Hi Kaveh,
> 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)
AFAIK, Roger Sayle implemented this if the equivalent thing happens in
a switch statement like
switch (foo)
{
case 1:
case 3:
case 7:
do_something ();
}
See
http://gcc.gnu.org/ml/gcc-patches/2003-01/msg01733.html
Perhaps we can generalize the switch statement handling to support the
if statement.
Kazu Hirata