https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107622
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- There is one part which GCC could optimize better that is the store. There might be another bug about that too. Note as I mentioned __builtin_unreachable is needed if truely the value coming inside g is outside of [0,3] range.