https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97856
Bug ID: 97856
Summary: Missed optimization: repeated call
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: miguel.ojeda.sandonis at gmail dot com
Target Milestone: ---
For code such as:
void f(int);
void g(int v) {
switch (v) {
case 1: f(1);
case 2: f(2);
case 3: f(3);
default: f(4);
}
}
GCC generates for e.g. x86_64:
g(int):
subq $8, %rsp
cmpl $2, %edi
je .L2
cmpl $3, %edi
je .L3
cmpl $1, %edi
je .L13
movl $4, %edi
addq $8, %rsp
jmp f(int)
.L13:
call f(int)
.L2:
movl $2, %edi
call f(int)
.L3:
movl $3, %edi
call f(int)
movl $4, %edi
addq $8, %rsp
jmp f(int)
Repeating the `f(4);` call can be avoided by reordering the cases, reducing
code size.