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

* [Bug target/54589] struct offset add should be folded into address calculation
  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 ` rguenth at gcc dot gnu.org
  2012-09-17  9:18 ` sgunderson at bigfoot dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-09-17  8:49 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*, i?86-*-*
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2012-09-17
          Component|tree-optimization           |target
     Ever Confirmed|0                           |1
            Summary|[missed-optimization]       |struct offset add should be
                   |struct offset add should be |folded into address
                   |folded into address         |calculation
                   |calculation                 |
      Known to fail|                            |4.6.3, 4.7.2, 4.8.0

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-09-17 08:49:25 UTC ---
As there is no loop involved it is RTL fwprop or combines job to eventually
do this.  I see

func:
.LFB517:
        .cfi_startproc
        movzbl  (%rsi), %eax
        addq    $1, %rax
        salq    $4, %rax
        movl    (%rdi,%rax), %eax
        movl    %eax, (%rdx)
        ret

for both 4.7 and 4.8.  i?86 is even worse.


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

* [Bug target/54589] struct offset add should be folded into address calculation
  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
  1 sibling, 0 replies; 3+ messages in thread
From: sgunderson at bigfoot dot com @ 2012-09-17  9:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from sgunderson at bigfoot dot com 2012-09-17 09:18:16 UTC ---
FWIW, in my original code, func() is a part of a loop body (it keeps reading
values from src in a loop). It doesn't really change anything in the generated
code, though.


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