public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joshua Haberman <jhaberman@gmail.com>
To: gcc@gcc.gnu.org
Subject: useless stores generated when returning a struct -- bug?
Date: Tue, 18 May 2010 18:06:00 -0000	[thread overview]
Message-ID: <loom.20100518T195020-391@post.gmane.org> (raw)

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

             reply	other threads:[~2010-05-18 18:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-18 18:06 Joshua Haberman [this message]
2010-05-19  0:09 ` Ian Lance Taylor
2010-05-19  0:19   ` Joshua Haberman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20100518T195020-391@post.gmane.org \
    --to=jhaberman@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).