http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46235
--- Comment #2 from Tony Poppleton <tony.poppleton at gmail dot com> 2011-01-28 16:55:48 UTC --- Based on Richard's comment, I tried a modified version of the code replacing the (1 << x) with just (16). This shows that GCC (4.6 & 4.5.2) does perform an optimization similar to llvm, and uses the testb instruction: movl %edi, %eax movl $1, %edx testb $16, %al cmove %edx, %eax ret Therefore, perhaps it would be beneficial to not convert from "a & (n << x)" to "(a >> x) & n", in the special case where the value n is 1 (or a power of 2 potentially)? Incidentally, the above code could have been optimized further to remove the usage of edx entirely (will make a separate PR about that)