https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67462
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |6.0 --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- The tree level should indeed do a better job here but it gets "confused" by narrowing the return expressions to int before it gets a chance to do that optimization. It's s64 d = a - b; if (d == 0) return (unsigned)a + (unsigned)c; else return (unsigned)b + (unsigned)d + (unsigned)c; to them and 'd' is not handled the same way because the shortening happens in the frontend. You might want to file a separate PR about this missed optimization.