https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106884
--- Comment #3 from Krister Walfridsson <kristerw at gcc dot gnu.org> --- A similar case is int r1, r2; int foo(int a, int s1, int s2) { if (a & (1 << s1)) return r1; if (a & (1 << s2)) return r1; return r2; } where reassoc2 optimizes this to always shift by s2.