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 21:15:20 -0500
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)

Paul Brook wrote:
Compiler can optimize it any way it wants,
as long as result is the same as unoptimized one.

We have an option for that. It's called -O0.

Pretty much all optimization will change the behavior of your program.

Now that's a bit TOO strong a statement, critical optimizations like
register allocation and instruction scheduling will generally not change
the behavior of the program (though the basic decision to put something
in a register will, and *surely* no one suggests avoiding this critical
optimization).

The important distinction is whether that difference is observable in valid programs. The whole point of langage standards is that they define what constitutes a valid program.

Valid programs is too narrow a set, you really do have to pay attention
to normal usage. I very well remember the Burroughs 5500 compiler, which
took advantage of the stack semantics allowed by the standard, but in
fact virtually all Fortran programs of the era assumed static allocation
since that's what every other compiler did. As a consequence the 5500
Fortran was completely useless, one factor that certainly caused
universities I was aassociated with to avoid this machine.

You can argue that signed overflow is an extension that it's worth supporting by default. Other people (eg. those interested in autovectorization) will argue that it provides useful optimization opportunities. I don't know which of these is better, but either what it's a lot different to saying "never change the behavior of any program.

Yes, absolutely, I agree with that!




reply via email to

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