This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Document arithmetic overflow semantics


On Thu, 13 Feb 2003 14:24:14 -0800, Richard Henderson <rth@redhat.com> said:
> On Fri, Feb 14, 2003 at 05:27:46AM +1100, Fergus Henderson wrote:

>> `+wrap' is associative ...  But `+undef' is not

> Certainly it is.  It's undefined.

I don't think so.  The expressions

  INT_MAX +undef (1 +undef -1)

and

  (INT_MAX +undef 1) +undef -1

are different.  The former is required to be INT_MAX; the latter is
undefined behavior.  So if we might later apply optimizations that are
only valid when we hit undefined behavior, we can't transform the
former into the latter.  (Though there is a solution: we could
transform +undef into +wrap when associating.  That should be safe, I
think?)

I would be curious to see situations where +undef and -undef open up
interesting optimization possibilities.  It seems to me that making +
and - undefined is of a different nature than making * undefined; and
of course the earlier example of (A*2)/2 that profits from making *
undefined doesn't have a direct analog with + and -.  And I suspect
that there's a lot more code out there that depends on + and -
behaving the same for signed and unsigned than there is code that
depends on * behaving the same for signed and unsigned.

David Carlton
carlton@math.stanford.edu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]