http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47920
--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2011-02-28 09:56:36 UTC --- Presumably because arithmetic right-shift by 3 isn't the same as a division by 8 when (a+7) is negative. Changing the types to unsigned gives the code you want.