This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: dead code remover under gcc -O and higher(Is there a flag to do this)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "chengjian (D)" <cj dot chengjian at huawei dot com>
- Cc: gcc at gcc dot gnu dot org, Li Bin <huawei dot libin at huawei dot com>, "Xiexiuqi (Xie XiuQi)" <xiexiuqi at huawei dot com>
- Date: Mon, 4 Dec 2017 09:20:44 +0100
- Subject: Re: dead code remover under gcc -O and higher(Is there a flag to do this)
- Authentication-results: sourceware.org; auth=none
- References: <abf9d156-a3db-58b8-26d2-d4c4159b1481@huawei.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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