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: Robert Dewar
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 08:49:43 -0500
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)

Paolo Bonzini wrote:
We've optimized expressions such as (a*2)/2 on the basis of overflow being undefined for a very long time, not just loops.
What is (a*2)/2 optimized to? certainly it has the value a if you wrap, so you are not necessarily depending on undefined here.

it's interesting that in Ada, intermediate values are allowed to go out
of range, skipping the overflow check (i.e. if intermediate things go
out of range, you are allowed to raise Constraint_Error, but you can
give the right answer instead.

So Ada is allowed to return (a*2)/2 as a for the signed case without
appealing to any undefinedness, and in general (a*b)/c can always
be done with a double length intermediate result (which is probably
the right implementation in C as well).




reply via email to

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