Il 12/11/2013 13:16, Peter Maydell ha scritto: > On 12 November 2013 12:09, Paolo Bonzini <pbonz...@redhat.com> wrote: >> Il 12/11/2013 12:07, Peter Maydell ha scritto: >>> For the compiler to eliminate this we are relying on: >>> * dead-code elimination of code following a 'break' >>> statement in a case block >>> * constant-folding of "something || 1" to 1 >>> * the compiler having done enough reasoning to be >>> sure that env is not NULL >> >> Yes, it's not trivial, but there are simpler ways to do it. >> >> For example there is no need to make sure that env is non-NULL, only to >> see that "something || 1" is never zero and thus "if (x) y;" is just >> "(void)x; y;". This seems easier to me than DCE after "break" which >> clang is able to do. > > You seem to be trying to reason about what the compiler > might choose to do or how it might be implemented internally.
I'm not reasoning about that in general (I was in the context of the message you quoted). I'm saying it's *reasonable* to expect that "-O0" means "reduce compile time, make debugging produce expected results, and try (not too hard) to not break what works at -O2". It's a simple QoI argument based on the fact that people *will* switch back and forth between -O2 and -O0. Of course not everything can be kept to work, since the compilers do pretty surprising optimizations (not counting the ones that break your code of course...). But I think a limited amount of dead code elimination *should* be expected because most people are now preferring "if" to "#ifdef" for compiling out code. If -O0 does not do that, let's move debug builds to -O1. Paolo