Bug 41749

Summary: non-needed instructions are not removed (not optimized)
Product: gcc Reporter: Коренберг Марк <socketpair>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: minor CC: gcc-bugs
Priority: P3    
Version: 4.3.3   
Target Milestone: 4.4.0   
Host: Target:
Build: Known to work: 4.4.0
Known to fail: 4.3.4 4.3.3 Last reconfirmed:

Description Коренберг Марк 2009-10-19 07:10:20 UTC
int main (void) {    return 1; }

Ubuntu Jaunty.

gcc --save-temps -fno-stack-protector -fomit-frame-pointer -Os ./cpuid.c

generates thgis:
--------------
main:
	leal	4(%esp), %ecx
	andl	$-16, %esp
	pushl	-4(%ecx)
	movl	$1, %eax
	pushl	%ecx
	popl	%ecx
	leal	-4(%ecx), %esp
	ret
--------------------------
why i get this:
	pushl	%ecx
	popl	%ecx
and other non-needed instructions (for another example)
pushl	%ebp
andl	$1, %eax
movl	%esp, %ebp
pushl	%ecx
popl	%ecx
popl	%ebp

These instructions are not optimized not in -O3, nor in -Os
Comment 1 Коренберг Марк 2009-10-19 07:14:32 UTC
gcc322 generates this:
(gcc -Os -fomit-frame-pointer qwe.c --save-temps)

main:                                                              
        movl    $1, %eax                                           
        ret                                                        

WTF?
Comment 2 Richard Biener 2009-10-19 10:58:22 UTC
It aligns the incoming stack.  Fixed in 4.4/4.5.