On Mon, Dec 04, 2017 at 08:56:05AM +0800, chengjian (D) wrote:
> So my question is :
> It seems that one of the optimization options in the -O1 option eliminates
> the dead code, I have seen the optimize doccument about GCC
> 
> https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Optimize-Options.html
> 
> but I can't find it.

-ftree-dce, -fdce (but actually many other passes do that, if some condition
is folded to a constant, any cfg cleanup will remove the dead code).

> So if I just want to compile this code under the -O0 option, Is it possible
> ? Are there some optimization flags help me to do this?

No.  The thing is, -O0 vs. -Og vs. -O1+/-Os are using different sets of
passes, and various passes have gates flag_foo_bar_baz && optimize or
similar, so even if you enable -ffoo-bar-baz, at -O0 it will not do
anything.  In your testcase, you need either inlining (which is at -O0 done
only for __attribute__((always_inline)) functions), or some IPA analysis on
the return value range (I think that is still unimplemented), but even if it
would be, it certainly wouldn't be done at -O0.

So, make it always_inline and it might happen to "work" at -O0, otherwise,
no, don't try that at -O0.

        Jakub

Reply via email to