This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC optimizes integer overflow: bug or feature?
- From: Gerald Pfeifer <gerald at pfeifer dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Paul Eggert <eggert at CS dot UCLA dot EDU>, gcc at gcc dot gnu dot org, bug-gnulib at gnu dot org
- Date: Mon, 1 Jan 2007 22:07:53 +0100 (CET)
- Subject: Re: GCC optimizes integer overflow: bug or feature?
- References: <20061218230847.GD3824@iam.uni-bonn.de> <87zm9k8wqr.fsf@penguin.cs.ucla.edu> <20061219055405.GB19329@iam.uni-bonn.de> <877iwo9q49.fsf@penguin.cs.ucla.edu> <m3fybbabxj.fsf@localhost.localdomain>
On Tue, 19 Dec 2006, Ian Lance Taylor wrote:
> Here is a quick list of optimizations that mainline gcc performs which
> rely on the idea that signed overflow is undefined. All the types
> are, of course, signed. I made have made some mistakes. I think this
> gives a good feel for the sorts of optimizations we can make with this
> assumption.
Thanks for compiling this exhaustive list, Ian!
Currently our documentation on -fwrapv is rather short and does not
provide examples or anything to provide such a feel:
This option instructs the compiler to assume that signed arithmetic
overflow of addition, subtraction and multiplication wraps around
using twos-complement representation. This flag enables some
optimizations and disables others. This option is enabled by default
for the Java front-end, as required by the Java language specification.
"This flag enables some optimizations and disables others" is all we
have. I wonder whether you could perhaps add (part of) your list to
this documentation? Or would that be too specific?
Gerald