public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Optimization flags not working (GCC 4.2.4)
@ 2009-04-03 19:31 slnc
  2009-04-03 21:45 ` John (Eljay) Love-Jensen
  0 siblings, 1 reply; 7+ messages in thread
From: slnc @ 2009-04-03 19:31 UTC (permalink / raw)
  To: gcc-help

I have a file called "main.c":

-- main.c ------------------------------------------
int main(void) {
	int i, j;

	for (i = 0; i < 10; i ++)
		j = 5;

	return 0;
}
----------------------------------------------------

When I compile it with "gcc -O1 -c -o main.o main.c" and I do an 
"objdump -d main.o" I get:

------------------------------------------------------
main.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <main>:
    0:	31 c0                	xor    %eax,%eax
    2:	c3                   	retq
------------------------------------------------------


But when I try to use just only one optimization flag by compiling with 
"gcc -ftree-dce -c -o main.o main.c" the optimization flag seems to do 
nothing at all:

------------------------------------------------------
main.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <main>:
    0:	55                   	push   %rbp
    1:	48 89 e5             	mov    %rsp,%rbp
    4:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%rbp)
    b:	eb 0b                	jmp    18 <main+0x18>
    d:	c7 45 f8 05 00 00 00 	movl   $0x5,-0x8(%rbp)
   14:	83 45 fc 01          	addl   $0x1,-0x4(%rbp)
   18:	83 7d fc 09          	cmpl   $0x9,-0x4(%rbp)
   1c:	7e ef                	jle    d <main+0xd>
   1e:	b8 00 00 00 00       	mov    $0x0,%eax
   23:	c9                   	leaveq
   24:	c3                   	retq
------------------------------------------------------


And even if I specify all the optimization flags that are enabled by -O1 
I get the same previous objdump. What am I doing wrong?

Thank you,

-- 
Juan Alonso

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-04-04  1:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-03 19:31 Optimization flags not working (GCC 4.2.4) slnc
2009-04-03 21:45 ` John (Eljay) Love-Jensen
2009-04-03 23:55   ` slnc
2009-04-04  0:31     ` David Daney
2009-04-04  0:47       ` slnc
2009-04-04  0:58         ` Robert William Fuller
2009-04-04  1:01         ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).