This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Optimize attribute and inlining
- From: "Selvaraj, Senthil_Kumar" <Senthil_Kumar dot Selvaraj at atmel dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 25 Jul 2012 14:07:26 +0000
- Subject: Optimize attribute and inlining
Declaring a function with __attribute__((optimize("O0")) turns off inlining for the translation unit (atleast) containing the function (see output at the end). Is this expected behavior?
I tracked this down to the fact that when processing the optimize attribute with O0, flag_no_inline is set to 1 and is not restored back. The early_inliner pass in ipa-inline.c (obviously) skips processing if flag_no_inline is set, and therefore inlining does not occur. I did see that handle_optimize_attribute in c-family/c-common.c saves and restores whatever options have corresponding fields in struct cl_optimization, but inlining is not one of them. That I guess is happening because inline is not described as an "Optimization" option in common.opt.
Test output
----------------
$ cat test.c
static void callee() { static int a; a++; }
void caller() { callee(); }
$
$ ~/Code/gcc/repo/native_install/bin/gcc -O1 -fdump-tree-all -S test.c
$
$ cat test.c.*.optimized
;; Function caller (caller, funcdef_no=1, decl_uid=1358, cgraph_uid=1)
caller ()
{
int a.0;
int a.1;
static int a;
static int a;
<bb 2>:
a.0_3 = a;
a.1_4 = a.0_3 + 1;
a = a.1_4;
return;
}
$ cat test.c
static void callee() { static int a; a++; }
void caller() { callee(); }
static void somefunc() __attribute__((optimize("O0")));
$
$ ~/Code/gcc/repo/native_install/bin/gcc -O1 -fdump-tree-all -S test.c
$
$ cat test.c.*.optimized
;; Function callee (callee, funcdef_no=0, decl_uid=1355, cgraph_uid=0)
callee ()
{
static int a;
int a.1;
int a.0;
<bb 2>:
a.0_1 = a;
a.1_2 = a.0_1 + 1;
a = a.1_2;
return;
}
;; Function caller (caller, funcdef_no=1, decl_uid=1358, cgraph_uid=1)
caller ()
{
<bb 2>:
callee ();
return;
}
Regards
Senthil