This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Document arithmetic overflow semantics
On Thu, Feb 13, 2003 at 11:16:03AM -0700, Roger Sayle wrote:
>
> > > I'm prepared to drop this entire argument if you can find me just one
> >
> > The one I mentioned: (a*2)/2.
>
>
> That'll do. You're right, GCC does optimize this assuming undefined
> overflow. Good to my word, I hereby withdraw my patch. There are
> more bugs in this area, than I can hope to address.
>
> Interestingly, Microsoft's Visual C/C++ compilers don't optimize this
> example. I wonder how much of their 20% SPECint advantage over mainline
> GCC is from their use of two's-complement semantics vs. undefined
> overflow. For example, they also optimize "z1 = (x+y)+z; z2 = x+(y+z)"
> which GCC currently can't.
But undefined overflow is a superset of two's complement semantics; if
overflow is undefined it can be implemented as two's complement if it is
useful.