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: Integer Overflow/Wrap and GCC Optimizations


On 1/24/2013 10:33 AM, Jeffrey Walton wrote:

In this case, I claim we must perform the operation. Its the result
that we can't use under some circumstances (namely, overflow or wrap).

You do not have to do the operation if the program has an overflow. The compiler can reason about this, so for example

      a = b + 1;
      if (a < b) ...

The compiler can assume that the test is true, because the only
conceivable way it would be false is on an overflow that wraps,
but that's undefined. If a is not used other than in this test,
the compiler can also eliminate the addition and the assignment



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