Bug 6052

Summary: suboptimal code
Product: Sisyphus Reporter: Alexey Voinov <voins>
Component: gcc4.4Assignee: Gleb F-Malinovskiy <glebfm>
Status: CLOSED WORKSFORME QA Contact: qa-sisyphus
Severity: normal    
Priority: P2 CC: glebfm
Version: unstable   
Hardware: all   
OS: Linux   

Description Alexey Voinov 2005-02-07 13:07:21 MSK
$ cat > test.c
extern int g(int);
int f(int x) { return g(x); }

$ gcc -S -O3 test.c -o -
	.file	"test.c"
	.text
	.p2align 4,,15
.globl f
	.type	f, @function
f:
	pushl	%ebp
	movl	%esp, %ebp
	popl	%ebp
	jmp	g
	.size	f, .-f
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.4.3 20050104 (ALT Linux, build 3.4.3-alt2)"

Obviously, pushl/movl/popl code does nothing and can be completely ommited.
Comment 1 Michael Shigorin 2006-05-13 18:24:18 MSD
look at 4.1?
Comment 2 Dmitry V. Levin 2006-05-27 03:02:41 MSD
Same with gcc-4.1.1; maybe I should report it upstream? :)
Comment 3 Kirill A. Shutemov 2010-11-04 23:25:37 MSK
It seems fixed in gcc4.5:

$ gcc -S -O3 test.c -o -
        .file   "test.c"
        .text
        .p2align 4,,15
.globl f
        .type   f, @function
f:
.LFB0:
        .cfi_startproc
        jmp     g
        .cfi_endproc
.LFE0:
        .size   f, .-f
        .ident  "GCC: (GNU) 4.5.1 20100924 (ALT Linux 4.5.1-alt1)"
        .section        .note.GNU-stack,"",@progbits