public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/54589] New: [missed-optimization] struct offset add should be folded into address calculation
@ 2012-09-15 13:37 sgunderson at bigfoot dot com
  2012-09-17  8:49 ` [Bug target/54589] " rguenth at gcc dot gnu.org
  2012-09-17  9:18 ` sgunderson at bigfoot dot com
  0 siblings, 2 replies; 3+ messages in thread
From: sgunderson at bigfoot dot com @ 2012-09-15 13:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54589

             Bug #: 54589
           Summary: [missed-optimization] struct offset add should be
                    folded into address calculation
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sgunderson@bigfoot.com


Hi,

I found this in 4.4 (Ubuntu 10.04), and have confirmed it's still there in

  gcc (Debian 20120820-1) 4.8.0 20120820 (experimental) [trunk revision 190537]

This code:

  #include <emmintrin.h>

  struct param {
          int a, b, c, d;
          __m128i array[256];
  };

  void func(struct param *p, unsigned char *src, int *dst)
  {
          __m128i x = p->array[*src];
          *dst = _mm_cvtsi128_si32(x);
  }

compiles with -O2 on x86-64 to this assembler:

  0000000000000000 <func>:
     0:    0f b6 06                 movzbl (%rsi),%eax
     3:    48 83 c0 01              add    $0x1,%rax
     7:    48 c1 e0 04              shl    $0x4,%rax
     b:    8b 04 07                 mov    (%rdi,%rax,1),%eax
     e:    89 02                    mov    %eax,(%rdx)
    10:    c3                       retq   

The add should be folded into the address calculation here. (The shl can't,
because it's too big.) Curiously enough, if I misalign the struct element by
removing c and d, and declaring the struct __attribute__((packed)), GCC will do
that; the mov will then be from $8(%rdi,%rax,1),%eax and there is no redundant
add.


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

end of thread, other threads:[~2012-09-17  9:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-15 13:37 [Bug tree-optimization/54589] New: [missed-optimization] struct offset add should be folded into address calculation sgunderson at bigfoot dot com
2012-09-17  8:49 ` [Bug target/54589] " rguenth at gcc dot gnu.org
2012-09-17  9:18 ` sgunderson at bigfoot dot com

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