https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124383
Bug ID: 124383
Summary: cold attribute causes an extra jump
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
Target Milestone: ---
[hjl@gnu-tgl-3 pr47253]$ cat cold-3.c
extern void bar1 (void);
extern void bar2 (void) __attribute__((__cold__));
extern void bar3 (void) __attribute__((__cold__));
void
foo (int status)
{
switch (status)
{
case 1:
bar1 ();
return;
case 2:
bar2 ();
return;
case 3:
bar3 ();
return;
}
}
[hjl@gnu-tgl-3 pr47253]$ /usr/gcc-16.0.1-x32/bin/gcc -S -O2 cold-3.c
[hjl@gnu-tgl-3 pr47253]$ cat cold-3.s
.file "cold-3.c"
.text
.section .text.unlikely,"ax",@progbits
.LCOLDB0:
.text
.LHOTB0:
.p2align 4
.globl foo
.type foo, @function
foo:
.LFB0:
.cfi_startproc
cmpl $1, %edi
je .L2
testl %edi, %edi
jle .L1
cmpl $2, %edi
je .L4
cmpl $3, %edi
je .L7 <<< This can be replaced with "je .L5".
.L1:
ret
.p2align 4,,10
.p2align 3
.L2:
jmp bar1
.L7:
jmp .L5
.cfi_endproc
.section .text.unlikely
.cfi_startproc
.type foo.cold, @function
foo.cold:
.LFSB0:
.L4:
jmp bar2
.L5:
jmp bar3
.cfi_endproc
.LFE0:
.text
.size foo, .-foo
.section .text.unlikely
.size foo.cold, .-foo.cold
.LCOLDE0:
.text
.LHOTE0:
.ident "GCC: (GNU) 16.0.1 20260202 (experimental)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-tgl-3 pr47253]$