https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66872
James Almer <jamrial at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jamrial at gmail dot com --- Comment #1 from James Almer <jamrial at gmail dot com> --- Ideally, for -mbmi2 (which is enabled with -march=haswell) the compiler should generate a single bzhi instruction instead, as i mentioned in pr65871. The generated code for your example would then be bzhi %esi, %edi, %eax ret Also, left shift of negative value is undefined behavior in C. Try compiling that code with -Wshift-negative-value using gcc trunk.