bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GCC optimizes integer overflow: bug or feature?


From: Joe Buck
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 13:21:02 -0800
User-agent: Mutt/1.4.1i

On Tue, Dec 19, 2006 at 12:05:44PM -0800, 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.

There are two different sets of cases: those where gcc's behavior is
consistent with the assumption that signed overflow wraps, and those
that are not consistent with that assumption.  For all common targets,
the signed integer instructions actually do wrap, and the result is that
when people compile without optimization, this is what they observe,
and what they unconsciously assume.

For example:

> * Fold ((A + C1) cmp C2) to (A cmp (C1 + C2)) where C1 and C2 are
>   constants, and likewise for -.

If cmp is == or !=, this are consistent with the assumption that overflow
wraps.  For <, <=, >, >= it is not.

For that reason, it might be more appropriate to warn about cases where
gcc might do an optimization that is *not* consistent with the "wrap"
assumption.  Otherwise there will be way too much noise.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]