------- Comment #2 from rguenth at gcc dot gnu dot org 2009-05-07 09:36 ------- Of course this only works if logicals are zero-extended.
We manage to fold int foo(unsigned char b) { return b | 0xff; } but not int bar(unsigned char b) { return b & (~0 << 8); } appearantly because the C FE for the former generates (int) (b | 255) because of some premature optimization in build_binary_op. We still do not fold int foo(unsigned char b) { return b | 0xfff; } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40052