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: Paolo Bonzini
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 14:39:51 +0100
User-agent: Thunderbird 1.5.0.8 (Macintosh/20061025)


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.

No, it has not. For example, if a is 0x40000000 in a 32 bit type and arithmetic wraps, a*2 = -0x80000000 (overflow), and hence (a*2)/2 = -0x40000000 = -1073741824.

Paolo




reply via email to

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