[Bug middle-end/64309] if (1 & (1 << n)) not simplified to if (n == 0)
glisse at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Dec 15 21:06:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64309
--- Comment #11 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Oleg Endo from comment #7)
> (1 << n) & 6 != 0 -> n > 0 && n < 3 (not beneficial)
We usually spell it (unsigned)n-1<2 (still not that great).
(In reply to Marek Polacek from comment #8)
> > > I don't think so. I tried to come up with a more general transformation
> > > that would simplify ((CST << n) & CST) != 0, but I haven't found anything
> >
> > If both CST are (possibly different) powers of 2 it works.
>
> Yes, but I'm not sure if it's worth it (doing it for 1, 2, 4, 8, ... instead
> of just for 1).
I am not sure why 1 is so much more important than the others...
> > ((c<<n)&c)==c also works. ((pow2<<p)&(pow2<<n))!=0.
>
> I don't see how's that a simplification.
((c<<n)&c)==c -> n==0
((pow2<<p)&(pow2<<n))!=0 -> p==n
More information about the Gcc-bugs
mailing list