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...) ???


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


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