On Tue, 27 Oct 2015, Richard Biener wrote: > When factoring a*b + a*c to (b + c)*a we have to guard against the > case of a == 0 as after the factoring b + c might overflow in that > case. Fixed by doing the addition in an unsigned type if required.
The same applies to a == -1 (consider b and c equal to -(INT_MIN/2), when a*b + a*c is INT_MIN but b+c overflows). In that case, if you avoid b+c overflowing using an unsigned type, but convert back to signed for the multiplication, you get a spurious overflow from the multiplication instead. -- Joseph S. Myers jos...@codesourcery.com