Gabriel Dos Reis wrote:
I don't believe this particular issue of optimization based on "undefined behaviour" can be resolved by just telling people "hey look, the C standard says it is undefined, therefore we can optimize. And if you're not happy, just tell the compiler not to optimize". For not all undefined behaviour are equal, and undefined behaviour is also a latitude given to implementors to better serve their base users.
Right, and better service is a combination of doing what is expected and generating fast code, and sometimes the two do conflict, and then we have to do the best we can to balance the conlicting goals. My concern is that in achieving this balance, we really need to have data to show that we are indeed generating significantly faster code. Compiler writers tend to want to optimize the last instruction out in any situation, without necessarily showing it is significant to do so.