Hi, On Wed, 16 Nov 2016, Marc Glisse wrote:
> > > The first sentence about ORing the sign bit sounds strange (except for a > > > sign-magnitude representation). With 2's complement, INT_MIN is -2^31, the > > > divisors are the 2^k and -(2^k). -2 * 2^30 yields INT_MIN, but your test > > > misses -2 as a possible divisor. On the other hand, 0b100...001 (aka > > > -INT_MAX) > > > is not a divisor of INT_MIN but your test says the reverse. > > > > Yeah, but it handled the testcase ;) So I guess the easiest would be > > to check integer_pow2p (abs (TREE_OPERAND (t, 0)) then, thus > > wi::popcount (wi::abs (TREE_OPERAND (t, 0))) == 1? > > Looks good to me, thanks. An integer X is a power of two if and only if X & -X == 0 (&& X != 0 if you want to exclude zero) which also nicely handles positive and negative numbers at the same time. No need for popcounts or abs. Ciao, Michael.