This is the mail archive of the gcc-patches@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: Tiny combine tweek


> Jan Hubicka <jh@suse.cz> writes:
> 
> >> > int
> >> > t(int a)
> >> > {
> >> >   a=a&8;
> >> >   a=a<<1;
> >> >   a=a>>1;
> >> >   return a;
> >> > }
> >> > don't need to do the shifts. GCC used to simplify this but it does not
> >> > do that anymore.
> >> 
> >> I'm sick and not thinking clearly ... could you please explain in
> >> small words how we get an IF_THEN_ELSE construct out of that?
> >
> > Combine sees (a<<1)>>1 expression and decides to be smart by noticing
> > that a has two possible values (via nonzero_bits).  It converts it then
> > a?const1:const2 early instead of noticing that the shifts are noops.
> 
> Wouldn't it be better to notice that the pair of shifts is a noop at
> the time the IF_THEN_ELSE construct would otherwise be generated?

That code is somewhat generic (what it does is to recursivly walk the
RTL and try to convert these into if_then_elses - so it first creates if
then else form of "a", then "a<<1" and so on).

It would be possible to reorder the optimizations so first the normal
simplification of shifts is done and later we do this trick, but it
needs more changes too (the combine_simplify_rtx would need to not
return out of each case of the large switch separately) and doing so
this way can possibly catch some extra cases where such a noop
if_then_else is constructed for different reasons...

Honza
> 
> zw


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