This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Code bloat for simple, linear code.


Hi.

I just observed a code bloat for gcc in a rather simple test case.

The test is done with avr-gcc 4.7.0 from the current snapshot (SVN
172902) but I also see it on older versions like 4.5.2.

avr-gcc called with -Os -c

gcc puts a great deal of the variables on the stack and uses them just
once which causes the code bloat.

This looks like a target-independent artifact and it should be able to
reproduce on other targets.

I wonder if there is a magic switch to avoid that "optimization"?
Some variables are added several times in the test code, but gcc has
already reordered them to the same place.

For AVR a stack frame is set up that costs 50 instructions and 15
slots, the accesses to stack add to the bloat, too.

Johann

#define TYP char

#define XCHAR(X)                               \
    extern TYP x ## X ## 0;                    \
    extern TYP x ## X ## 1;                    \
    extern TYP x ## X ## 2;                    \
    extern TYP x ## X ## 3;                    \
    extern TYP x ## X ## 4;                    \
    extern TYP x ## X ## 5;                    \
    extern TYP x ## X ## 6;                    \
    extern TYP x ## X ## 7;                    \
    extern TYP x ## X ## 8;                    \
    extern TYP x ## X ## 9

#define ACHAR(X)                                \
    check = check + x ## X ## 0;                \
    check = check + x ## X ## 1;                \
    check = check + x ## X ## 2;                \
    check = check + x ## X ## 3;                \
    check = check + x ## X ## 4;                \
    check = check + x ## X ## 5;                \
    check = check + x ## X ## 6;                \
    check = check + x ## X ## 7;                \
    check = check + x ## X ## 8;                \
    check = check + x ## X ## 9

extern TYP check;

XCHAR(1);
XCHAR(2);
XCHAR(3);
XCHAR(4);
XCHAR(5);

void checksum (void)
{
    ACHAR(1);
    ACHAR(1);
    ACHAR(1);
    ACHAR(2);
    ACHAR(3);
    ACHAR(4);
    ACHAR(5);
    ACHAR(2);
    ACHAR(3);
    ACHAR(4);
}

Configured with: ../../gcc.gnu.org/trunk/configure --target=avr
--prefix=/local/gnu/install/gcc-4.7 --disable-nls --disable-shared
--enable-languages=c
Thread model: single
gcc version 4.7.0 20110423 (experimental) (GCC)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]