[IRA] Code bloat due to register spills in v9, v10, v11, v12 and master

Georg-Johann Lay avr@gjlay.de
Fri Dec 9 19:23:02 GMT 2022

There is the following code size regression, filed as


Simple test cases are, for example

#define PORT (*((unsigned char volatile*) 0x24))

unsigned short var16;

void func (void)
     if (2048000ul * var16 > 1200000ul)
         PORT |= 1;

When I compile it with

$ avr-gcc -Os bloat1.c -c && avr-size bloat1.o

the code size increases from 36 bytes (v8) to 88 bytes (v13).

Apart from that, register pressure is much higher because a frame 
pointer is set up for no reason, and the values go through stack slots 
for no reason.

Even test cases which don't require any code like

long func2 (void)
     long var32;
     __asm ("; some code %0" : "=r" (var32));
     return var32;

increase in register pressure (x2), stack usage (from 0 to 6 bytes) and 
code size from 2 bytes (v8) to 34 bytes (v13).

Some projects like QMK "solved" the problem by declaring GCC > v8 to be 
"incompatible" with their project, see

In own projects I observed the problem, too, and the only solution is to 
use v8 or older.  Options like -fcaller-saves or -fira-algorithm= have 
no effect.

To configure, I used --target=avr --disable-nls --with-dwarf2 
--enable-languages=c,c++ --with-gnu-as --with-gnu-ld --disable-shared, 
so nothing special.

The problem is present in v9, v10, v11, v12 and master (future v13), so 
sitting around for quite a while, so maybe it's not fixed because RA 
maintainers are not aware of the problem.

Thanks for any help,


More information about the Gcc mailing list