Unexpected optimizer behavior

Andrew Haley aph@redhat.com
Sat Jun 27 07:58:00 GMT 2009


me22 wrote:
> 2009/6/26 Frank Neuhaus <dtag00@gmail.com>:
>> Yes I agree that since resize is not inlined, the way pixels changes
>> during the resize call is unknown to the optimizer operating on main.
>> But _after_ this call to resize, all changes to pixels _have_ to be
>> caused by main, and thus are known to the optimizer of the main
>> function. That means it should be able to tell that pixels cannot
>> possibly change after the execution of resize(*). And more
>> specificially that it cannot possibly change during the execution of
>> the loop.
>>
> 
> What if resize spawns a thread that wakes up periodically to change
> the value?  The compiler can't assume "well-behaved" functions.

Yes, it can and it does.  This would be undefined behaviour.

Andrew.



More information about the Gcc-help mailing list