On Wed, Jul 25, 2012 at 4:07 PM, Selvaraj, Senthil_Kumar <senthil_kumar.selva...@atmel.com> wrote: > 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?
Not really. The optimize attribute processing should only affect flags it saves. -f[no-]inline is not meaningful per function and we have the noinline attribute for more proper handling. That said, I consider the optimize attribute code seriously broken and unmaintained (but sometimes useful for debugging - and only that). > 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