https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126967
Bug ID: 126967
Summary: [avr] missed branch optimization
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gjl at gcc dot gnu.org
Target Milestone: ---
char func (char x)
{
if (x == 0x20) goto L1;
if (x > 0x20) goto L2;
return 0;
L1: __asm ("nop ; 1");
L2: __asm ("nop ; 2");
return x;
}
$ avr-gcc-17 x.c -S -Os
Generates the following asm:
func:
cpi r24,lo8(32) ; 42 [c=4 l=1] cmpqi3/0
brne .L2 ; 43 [c=4 l=1] branch
nop ; 1
.L3:
nop ; 2
ret ; 37 [c=0 l=1] return
.L2:
brlt .L5 ; 44 [c=4 l=1] branch
rjmp .L3 ; 52 [c=4 l=1] jump
.L5:
ldi r24,0 ; 45 [c=4 l=1] movqi_insn/0
ret ; 48 [c=0 l=1] return
Notice jump insns 44 and 52 that are doing
if (REG_CC < 0)
goto .L5
goto .L3
.L5:
which would better be:
if (REG_CC >= 0)
goto .L3
.L5:
i.e.
brge .L3 ; if (REG_CC >= 0) goto .L3
.L5:
Target: avr
Configured with: ../../source/gcc-master/configure --target=avr --disable-nls
--with-dwarf2 --with-gnu-as --with-gnu-ld --with-long-double=64
--disable-libcc1 --disable-analyzer --enable-languages=c,c++
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260817 (experimental) (GCC)