https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97784
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Reassociation is done for signed types and places where it could introduce overflows. If you -fwrapv, you should get the optimization. Likewise for unsigned types.