public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* useless stores generated when returning a struct -- bug?
@ 2010-05-18 18:06 Joshua Haberman
  2010-05-19  0:09 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Haberman @ 2010-05-18 18:06 UTC (permalink / raw)
  To: gcc

I have a case where I think useless stores are being generated, but I
want to be sure before I file a bug.  This is with gcc 4.4.3 on Ubuntu
10.04, x86-64.

I have been experimenting with returning structs from functions instead
of passing pointers to "out" parameters.  This seems like it should be
more optimizer-friendly because you can avoid taking addresses of local
variables, which prevents them from possibly being aliased.

However in this test case, gcc is generating four stores that appear to
be completely useless:

#include <stdint.h>

struct twoints { uint64_t a, b; } foo();
void bar(uint64_t a, uint64_t b);

void func() {
  struct twoints s = foo();
  bar(s.a, s.b);
}

$ gcc -Wall -c -o testbad.o -msse2 -O3 -fomit-frame-pointer testbad.c-
$ objdump -d -r -M intel testbad.o

testbad.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <func>:
   0:   48 83 ec 28             sub    rsp,0x28
   4:   31 c0                   xor    eax,eax
   6:   e8 00 00 00 00          call   b <func+0xb>
                        7: R_X86_64_PC32        foo-0x4
   b:   48 89 04 24             mov    QWORD PTR [rsp],rax
   f:   48 89 54 24 08          mov    QWORD PTR [rsp+0x8],rdx
  14:   48 89 d6                mov    rsi,rdx
  17:   48 89 44 24 10          mov    QWORD PTR [rsp+0x10],rax
  1c:   48 89 54 24 18          mov    QWORD PTR [rsp+0x18],rdx
  21:   48 89 c7                mov    rdi,rax
  24:   48 83 c4 28             add    rsp,0x28
  28:   e9 00 00 00 00          jmp    2d <func+0x2d>
                        29: R_X86_64_PC32       bar-0x4

Why is it storing rax and rdx to the stack twice?  These stores are never
used AFAICS.

Josh

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

* Re: useless stores generated when returning a struct -- bug?
  2010-05-18 18:06 useless stores generated when returning a struct -- bug? Joshua Haberman
@ 2010-05-19  0:09 ` Ian Lance Taylor
  2010-05-19  0:19   ` Joshua Haberman
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2010-05-19  0:09 UTC (permalink / raw)
  To: Joshua Haberman; +Cc: gcc

Joshua Haberman <jhaberman@gmail.com> writes:

> I have a case where I think useless stores are being generated, but I
> want to be sure before I file a bug.  This is with gcc 4.4.3 on Ubuntu
> 10.04, x86-64.

I concur that this is a missed optimization bug.

Ian

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

* Re: useless stores generated when returning a struct -- bug?
  2010-05-19  0:09 ` Ian Lance Taylor
@ 2010-05-19  0:19   ` Joshua Haberman
  0 siblings, 0 replies; 3+ messages in thread
From: Joshua Haberman @ 2010-05-19  0:19 UTC (permalink / raw)
  To: gcc

Ian Lance Taylor <iant <at> google.com> writes:
 
> Joshua Haberman <jhaberman <at> gmail.com> writes:
> 
> > I have a case where I think useless stores are being generated, but I
> > want to be sure before I file a bug.  This is with gcc 4.4.3 on Ubuntu
> > 10.04, x86-64.
> 
> I concur that this is a missed optimization bug.

Thanks Ian.  I'll file it as a bug.

Josh

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

end of thread, other threads:[~2010-05-19  0:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-18 18:06 useless stores generated when returning a struct -- bug? Joshua Haberman
2010-05-19  0:09 ` Ian Lance Taylor
2010-05-19  0:19   ` Joshua Haberman

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).