[Top][All Lists]

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

Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."

From: Vincent Lefevre
Subject: Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
Date: Sun, 31 Dec 2006 16:46:58 +0100
User-agent: Mutt/1.5.13-vl-r14963 (2006-12-20)

On 2006-12-31 10:07:44 -0500, Robert Dewar wrote:
> Vincent Lefevre wrote:
> >If done in unsigned, this won't lead to any optimization, as unsigned
> >arithmetic doesn't have overflows. So, if you write "a - 10" where a
> >is unsigned, the compiler can't assume anything, whereas is a is
> >signed, the compiler can assume that a >= INT_MIN + 10, reducing
> >the range for a, and possibly allowing some optimizations.
> Vincent, you missed the point, if we do this in unsigned, it works
> fine, and we don't WANT any optimization to intefere. That's what
> Richard was saying, if you want to do this kind of hand optimization
> of range checking, you do it in unsigned, and everything is fine.
> If you do it in signed expecting wrapping, then the optimization
> destroys your code. Yes, it is technically your fault, but this
> business of telling users

No, this isn't what I meant. The C standard doesn't assume wrapping,
so I don't either. If the compiler doesn't either, then it can do
some optimizations. Let's take a very simple example:

int not (int k)
  k + INT_MIN;
  (k - 1) + INT_MAX;
  /* Now the compiler can assume that k is either 0 or 1. Because
     otherwise there is an overflow and any result is correct. */
  return !k;

Is that clear? Note that if k were unsigned, the compiler could not

Of course, unless traps on overflows are enabled, the compiler won't
generate any code on the first two lines. But if combined with other
operations (with more complex code) and if the compiler assumes wrap
on overflow, then the compiler will not be able to optimize the k!.

Note: of course, this depends on the processor, one could also write
k & 1 here, and so on, but this is not my point here.

Vincent Lefèvre <address@hidden> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

reply via email to

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