Richard B. Kreckel wrote:
Bottom line: without such a warning, -fwrapv should be the default and should not be turned off by any -O option.
I agree with this. At least until -O2 no optimizations should be done by default if they can modify the result of an operation even if this might be a naive compiler user's assumption. As a "naive" user I know that without optimization compilers may output partially "strange" code. I remember a case (long time ago) when gcc without optimization produced something like mov ax, bx; mov bx, ax; which is complete nonsense because the 2nd operation is redundant. But that's ok because it's a side effect when the compiler doesn't search for redundant code. But for me this means I have to turn on some optimization to get reasonable code. And I expect that there is an optimization switch for "remove all redundant code and do all possible optimizations without changing the program logics". -O2 seemed to be quite common for this among different compilers. With -O3 I expect "modifying" optimizations to be done which means I have to be _really_ careful whether I can enable that optimization level. This is also ok. But if I can't rely on -O2 to be "safe" then I might be forced to disable optimization which also might mean that I should change the compiler. Please, don't get me wrong. I'm not sure how important this -fwrapv feature is to real world code but it sounds dangerous to me to do this optimization with -O2. And from my naive point of view I would expect that it would be enabled with -O3 or above, not with -O2. I personally do not care much about benchmark optimization because neither do I develop a benchmark nor do I use a benchmark for my daily work. And I think it's the same for 99% of all gcc users. If you _really_ need one single flag to optimize your benchmarks then introduce an -Obenchmark flag or so but, please, don't pollute -O2 with stuff that might produce highly optimized but not 100% reliable code. Andreas