public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/37774]  New: [4.4 Regression] Unnecessary load instruction in a loop
@ 2008-10-08 17:10 hjl dot tools at gmail dot com
  2008-10-08 20:07 ` [Bug middle-end/37774] " rguenth at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hjl dot tools at gmail dot com @ 2008-10-08 17:10 UTC (permalink / raw)
  To: gcc-bugs

Gcc 4.4 generates an extra load in a loop:

[hjl@gnu-6 gcc]$ cat /tmp/b.c 
#include <tmmintrin.h>

extern __m128i src[10];
extern __m128i resdst[10];

void
foo (void)
{
  int i;

  for (i = 0; i < 10; i++)
    resdst[i] = _mm_abs_epi16 (src[i]);
}
[hjl@gnu-6 gcc]$ gcc -O2 -S /tmp/b.c -o old.s -mssse3
-fno-asynchronous-unwind-tables
[hjl@gnu-6 gcc]$ gcc --version
gcc (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[hjl@gnu-6 gcc]$ cat old.s
        .file   "b.c"
        .text
        .p2align 4,,15
.globl foo
        .type   foo, @function
foo:
        xorl    %eax, %eax
        .p2align 4,,10
        .p2align 3
.L2:
        pabsw   src(%rax), %xmm0
        movdqa  %xmm0, resdst(%rax)
        addq    $16, %rax
        cmpq    $160, %rax
        jne     .L2
        rep
        ret
        .size   foo, .-foo
        .ident  "GCC: (GNU) 4.3.0 20080428 (Red Hat 4.3.0-8)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-6 gcc]$  ./xgcc -B./ -O2 -mssse3 -S /tmp/b.c
-fno-asynchronous-unwind-tables
[hjl@gnu-6 gcc]$ cat b.s
        .file   "b.c"
        .text
        .p2align 4,,15
.globl foo
        .type   foo, @function
foo:
        xorl    %eax, %eax
        .p2align 4,,10
        .p2align 3
.L2:
        movdqu  src(%rax), %xmm0
        pabsw   %xmm0, %xmm0
        movdqu  %xmm0, resdst(%rax)
        addq    $16, %rax
        cmpq    $160, %rax
        jne     .L2
        rep
        ret
        .size   foo, .-foo
        .ident  "GCC: (GNU) 4.4.0 20081006 (experimental) [trunk revision
140917]"

There are 2 problems:

1. Alignment info is lost and unaligned load is generated.
2. The load isn't needed at all.


-- 
           Summary: [4.4 Regression] Unnecessary load instruction in a loop
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hjl dot tools at gmail dot com


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


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

* [Bug middle-end/37774] [4.4 Regression] Unnecessary load instruction in a loop
  2008-10-08 17:10 [Bug middle-end/37774] New: [4.4 Regression] Unnecessary load instruction in a loop hjl dot tools at gmail dot com
@ 2008-10-08 20:07 ` rguenth at gcc dot gnu dot org
  2008-10-08 20:19 ` [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-10-08 20:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2008-10-08 20:06 -------
How is the load not needed?


-- 


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


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

* [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs
  2008-10-08 17:10 [Bug middle-end/37774] New: [4.4 Regression] Unnecessary load instruction in a loop hjl dot tools at gmail dot com
  2008-10-08 20:07 ` [Bug middle-end/37774] " rguenth at gcc dot gnu dot org
@ 2008-10-08 20:19 ` pinskia at gcc dot gnu dot org
  2008-10-08 20:53 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-10-08 20:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2008-10-08 20:18 -------
Just the alignment information is lost really:
(mem/s:V16QI (plus:SI (reg/f:SI 68)
                (reg:SI 63 [ ivtmp.68 ])) [4 resdst S16 A8])

Which I think is fixed via
http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00325.html .

The load is needed.

If we use a pointer instead of an array we get:
L2:
        pabsw   (%ecx,%eax), %xmm0
        movdqa  %xmm0, (%edx,%eax)
        addl    $16, %eax
        cmpl    $160, %eax
        jne     L2

Note since __m128i has the attribute of may_alias you have to do the load of
the global pointer before the loop.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2008-10-08 20:18:35
               date|                            |
            Summary|[4.4 Regression] Unnecessary|[4.4 Regression] Alignment
                   |load instruction in a loop  |information is lost for
                   |                            |ARRAY_REFs
   Target Milestone|---                         |4.4.0


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


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

* [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs
  2008-10-08 17:10 [Bug middle-end/37774] New: [4.4 Regression] Unnecessary load instruction in a loop hjl dot tools at gmail dot com
  2008-10-08 20:07 ` [Bug middle-end/37774] " rguenth at gcc dot gnu dot org
  2008-10-08 20:19 ` [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs pinskia at gcc dot gnu dot org
@ 2008-10-08 20:53 ` jakub at gcc dot gnu dot org
  2008-10-08 20:56 ` hjl dot tools at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-10-08 20:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2008-10-08 20:51 -------
Newer patch http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00350.html


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2008-
                   |                            |10/msg00350.html
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-10-08 20:18:35         |2008-10-08 20:51:43
               date|                            |


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


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

* [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs
  2008-10-08 17:10 [Bug middle-end/37774] New: [4.4 Regression] Unnecessary load instruction in a loop hjl dot tools at gmail dot com
                   ` (2 preceding siblings ...)
  2008-10-08 20:53 ` jakub at gcc dot gnu dot org
@ 2008-10-08 20:56 ` hjl dot tools at gmail dot com
  2008-10-09  8:19 ` jakub at gcc dot gnu dot org
  2008-10-09 11:30 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: hjl dot tools at gmail dot com @ 2008-10-08 20:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hjl dot tools at gmail dot com  2008-10-08 20:55 -------
(In reply to comment #3)
> Newer patch http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00350.html
> 

With this patch, I got

.globl foo
        .type   foo, @function
foo:
        xorl    %eax, %eax
        .p2align 4,,10
        .p2align 3
.L2:
        pabsw   src(%rax), %xmm0
        movdqa  %xmm0, resdst(%rax)
        addq    $16, %rax
        cmpq    $160, %rax
        jne     .L2
        rep
        ret

The load is combined into pabsw. The extra load insn and unaligned move
are gone.


-- 


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


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

* [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs
  2008-10-08 17:10 [Bug middle-end/37774] New: [4.4 Regression] Unnecessary load instruction in a loop hjl dot tools at gmail dot com
                   ` (3 preceding siblings ...)
  2008-10-08 20:56 ` hjl dot tools at gmail dot com
@ 2008-10-09  8:19 ` jakub at gcc dot gnu dot org
  2008-10-09 11:30 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-10-09  8:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2008-10-09 08:18 -------
Subject: Bug 37774

Author: jakub
Date: Thu Oct  9 08:17:08 2008
New Revision: 141003

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141003
Log:
        PR middle-end/37774
        * tree.h (get_object_alignment): Declare.
        * emit-rtl.c (set_mem_attributes_minus_bitpos): Call
        get_object_alignment if needed.
        * builtins.c (get_pointer_alignment): Move ADDR_EXPR operand handling
        to ...
        (get_object_alignment): ... here.  New function.  Try harder to
        determine alignment from get_inner_reference returned offset.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/emit-rtl.c
    trunk/gcc/tree.h


-- 


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


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

* [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs
  2008-10-08 17:10 [Bug middle-end/37774] New: [4.4 Regression] Unnecessary load instruction in a loop hjl dot tools at gmail dot com
                   ` (4 preceding siblings ...)
  2008-10-09  8:19 ` jakub at gcc dot gnu dot org
@ 2008-10-09 11:30 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-10-09 11:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2008-10-09 11:29 -------
Fixed.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2008-10-09 11:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-08 17:10 [Bug middle-end/37774] New: [4.4 Regression] Unnecessary load instruction in a loop hjl dot tools at gmail dot com
2008-10-08 20:07 ` [Bug middle-end/37774] " rguenth at gcc dot gnu dot org
2008-10-08 20:19 ` [Bug middle-end/37774] [4.4 Regression] Alignment information is lost for ARRAY_REFs pinskia at gcc dot gnu dot org
2008-10-08 20:53 ` jakub at gcc dot gnu dot org
2008-10-08 20:56 ` hjl dot tools at gmail dot com
2008-10-09  8:19 ` jakub at gcc dot gnu dot org
2008-10-09 11:30 ` jakub at gcc dot gnu dot org

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