https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68136
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2015-10-28 CC| |rguenth at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- int foo (s64 a, s64 b, s64 c) { s64 d = a - b; if (d == 0) return a + c; else return b + d + c; } ok, so the issue here is that the additions are narrowed to unsigned int because of the appearant cast to 'int' for the return while the d = a - b assignment is not narrowed in this way. (u32)b + (u32)(a - b) + (u32)c can not be easily simplified to the desired (u32)a + (u32)c. As 'd' is multi-use this way we don't change the compare to a == b either which would expose the then single-use 'd' to reassoc (which could get some tricks to perform narrowing). I don't see a very good answer here. Pattern-matching the whole thing is of course an option but I don't see that as a scalable solution. Maybe hacking up reassoc to do that narrowing trick and also consider non-single-use chains (marked specially so they only participate in simplification but never actual association or code-gen).