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!