Bug 59479 - Inlining of static function bloats code size when Os
Summary: Inlining of static function bloats code size when Os
Status: WAITING
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-12 07:39 UTC by bin.cheng
Modified: 2021-07-18 20:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-12-13 00:00:00


Attachments
The preprocessed file for newlib/libc/stdio/findfp.c (7.34 KB, text/x-eiffel)
2013-12-12 07:39 UTC, bin.cheng
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bin.cheng 2013-12-12 07:39:46 UTC
Created attachment 31424 [details]
The preprocessed file for newlib/libc/stdio/findfp.c

Hi, for attached preprocessed code from newlib/libc/stdio/findfp.c, GCC inlines static function `std' even when optimizing for Os.
With command line:
$ ./arm-none-eabi-gcc -Os -mthumb -mcpu=cortex-m0 -c -xc findfp.E -o findfp.o

The dumped symbols are like:
    21: 00000009    16 FUNC    GLOBAL DEFAULT    1 _cleanup_r
    ...
    29: 00000055   224 FUNC    GLOBAL DEFAULT    1 __sinit
    ...
    41: 000001d5    24 FUNC    GLOBAL DEFAULT    1 __fp_unlock_all

With command line:
$ ./arm-none-eabi-gcc -Os -mthumb -mcpu=cortex-m0 -c -xc findfp.E -o findfp.o -fno-inline

The dumped symbols are like:
     9: 00000018     0 NOTYPE  LOCAL  DEFAULT    1 $t
    10: 00000019    72 FUNC    LOCAL  DEFAULT    1 std.isra.0
    ...
    24: 00000009    16 FUNC    GLOBAL DEFAULT    1 _cleanup_r
    ...
    36: 0000009d    80 FUNC    GLOBAL DEFAULT    1 __sinit

This occurs on trunk and 4_8 branch.
Comment 1 Richard Biener 2013-12-13 11:00:28 UTC
I think you likely see a 2nd-order effect.  Inlining a once called function
should not increase code size.  But of course optimization opportunities
exposed by it may trigger optimizers that are not well tuned to honor -Os.

So, can you narrow down the issue a bit?
Comment 2 bin.cheng 2013-12-13 11:15:45 UTC
I will investigate it later.  Just clarifying, the function is called three times by the caller, it would increase code size usually.

BTW, could you explain a little about "2nd-order effect"?  I am not familiar with the concept.  Thanks in advance.
Comment 3 Andrew Pinski 2021-07-18 20:41:10 UTC
Is there a misunderstanding of what called once means?  Does it mean only called from one other function rather than one time?

I see std is called three times from __sinit rather than once in that function.