Various places in GCC use negate, bit-and and compare to test whether an integer is a power of 2, but I think it would be clearer for this test to be wrapped in a function.
OK for trunk?
commit e2ca9914ce46d56775854f50c21506b220fd50b6 Author: Jason Merrill <ja...@redhat.com> Date: Wed Sep 7 16:22:32 2016 -0400 * hwint.h (pow2p_hwi): New. diff --git a/gcc/hwint.h b/gcc/hwint.h index 6b4d537..3d85fc3 100644 --- a/gcc/hwint.h +++ b/gcc/hwint.h @@ -299,4 +299,12 @@ absu_hwi (HOST_WIDE_INT x) return x >= 0 ? (unsigned HOST_WIDE_INT)x : -(unsigned HOST_WIDE_INT)x; } +/* True if X is a power of two. */ + +inline bool +pow2p_hwi (unsigned HOST_WIDE_INT x) +{ + return (x & -x) == x; +} + #endif /* ! GCC_HWINT_H */