https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123999
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- Besides the -fwrapv idea we generally want to avoid associating signed overflow expressions for canonicalization (which is in the end done to allow CSE of leafs). But we do want association to cancel out ops or combine constants. When that happens we can rewrite the operation to wrapping arithmetic (unsigned), but it would be nice to shuffle operands back as much as possible to retain signed arith as written in untransformed IL. So, a + b + (c + d) - b would reliably become (int)((unsigned)a + (unsigned)(c + d)). As you said, the existing canonicalization is only a very weak CSE enabler. Instead doing chain collection upfront for the whole function (or suitable sub-parts) and identifying common subchains before emitting associated code would be useful. In fact reassoc can apply CSE itself here.
