> From: Robert Dewar <[EMAIL PROTECTED]>
>> Paul Schlie wrote:
> 
>> - You may be correct, although it's not obviously the case? (As requiring
>>   all undefined behavior be encapsulated between sequence points already
>>   seems implied to me, as I don't see any explicit counter examples
>>   requiring otherwise.
> 
> There don't need to be examples. The as-if rule always applies, if you cannot
> write a legitimate C program that shows the difference between two possible
> implementations, then both are correct.

??? as-if means they're logically equivalent (i.e. there is no logical
difference between the two alternative representations, and strongly support
that this should be the guideline for all optimizations).

>                                                Note that the requirement of a
> legitimate C program exlude ANY program which has undefined behavior anywhere.

Then it is illegitimate for a compiler to generate a program which contains
a known undefined behavior, (i.e. any known overflow, any unsigned to signed
cast which is known to not be representable, any pointer dereference of a
known null value, etc.; rather than generate any code.)

>>   Nor do any optimizations which are obviously more
>>   useful than potentially counterproductive seem to require the violation of
>>   C's sequence point semantics?)
> 
> Ordinary code motion optimizations like hoisting out of a loop are an obvious
> example, there are lots of others. If you read the dragon book (are you
> familiar with this book?) then almost all optimizations discussed there in the
> global optimization chapters would be affected.

Expression reordering does not necessitate the violation of sequence point
semantics as long as at the last point of reordering, the resulting
semantics are logically equivalent (as-if); which is why it's a safe
optimization if the logical behavior is preserved.


Reply via email to