public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2
@ 2013-04-23 16:25 tony.howard-co84udjx at yopmail dot com
  2013-04-24  8:10 ` [Bug tree-optimization/57051] " mpolacek at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: tony.howard-co84udjx at yopmail dot com @ 2013-04-23 16:25 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 57051
           Summary: Optimization regression in 4.8.0 from 4.7.2
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tony.howard-co84udjx@yopmail.com


The problem can be exhibited using the following snippet of code:

/* begin */
int total = 0;


inline void foo(int bar)
{
   total += bar*10;
}

void hello()
{
   for(int i = 0; i < 10; ++i)
   {
      foo(i);
   }
}
/* end */

With the option -O3,
gcc 4.7.2 and previous versions produce the following assembly code:
hello():
    addl    $450, total(%rip)
    ret

gcc 4.8.0 fails to optimize the code:
hello():
    movdqa    .LC0(%rip), %xmm0
    movdqa    %xmm0, %xmm2
    psrldq    $8, %xmm2
    paddd    %xmm2, %xmm0
    movdqa    %xmm0, %xmm3
    psrldq    $4, %xmm3
    paddd    %xmm3, %xmm0
    movdqa    %xmm0, %xmm4
    movd    %xmm4, -12(%rsp)
    movl    -12(%rsp), %eax
    addl    total(%rip), %eax
    addl    $170, %eax
    movl    %eax, total(%rip)
    ret


The results can be easily reproduced using http://gcc.godbolt.org/

The 4.7.2's configure options are:
Target: x86_64-linux-gnu

Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.7.2-11precise2' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object
--enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu

The 4.8.0's configure options are:
Target: x86_64-linux-gnu

Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.8.0-3ubuntu3~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu

The problem is not linked to Linaro or Ubuntu patches as it can be reproduced
as well on a stock version of gcc 4.8.0


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

* [Bug tree-optimization/57051] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
@ 2013-04-24  8:10 ` mpolacek at gcc dot gnu.org
  2013-04-24  8:30 ` [Bug tree-optimization/57051] [4.8/4.9 Regression] " rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-04-24  8:10 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> 2013-04-24 08:10:21 UTC ---
Well, one thing differs, 4.7 with -O3 aligns 'total' to
.align 16
whereas 4.8 with -O3 -fno-tree-vectorize has
.align 4


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

* [Bug tree-optimization/57051] [4.8/4.9 Regression] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
  2013-04-24  8:10 ` [Bug tree-optimization/57051] " mpolacek at gcc dot gnu.org
@ 2013-04-24  8:30 ` rguenth at gcc dot gnu.org
  2013-04-24 10:44 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-04-24  8:30 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |4.7.3
            Version|unknown                     |4.8.0
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2013-04-24
                 CC|                            |glisse at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
     Ever Confirmed|0                           |1
            Summary|Optimization regression in  |[4.8/4.9 Regression]
                   |4.8.0 from 4.7.2            |Optimization regression in
                   |                            |4.8.0 from 4.7.2
   Target Milestone|---                         |4.8.1

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> 2013-04-24 08:30:06 UTC ---
It seems scev_cprop doesn't do its job here.

(get_scalar_evolution
  (scalar = total.1_8)
  (scalar_evolution = {pretmp_14, +, _6 + 10}_1))

that's ok - SCCP doesn't provide any info in dumps, but I suppose it
fails to compute the number of iterations here(!?).

And we don't constant-fold the vectorized code:

  pretmp_14 = total;
  vect_total.18_44 = { 40, 60, 80, 100 } v>> 64;
  vect_total.18_45 = vect_total.18_44 + { 40, 60, 80, 100 };
  vect_total.18_46 = vect_total.18_45 v>> 32;
  vect_total.18_47 = vect_total.18_46 + vect_total.18_45;
  stmp_total.17_48 = BIT_FIELD_REF <vect_total.18_47, 32, 0>;
  vect_total.19_49 = stmp_total.17_48 + pretmp_14;
  total.1_9 = vect_total.19_49 + 80;
  total.1_20 = vect_total.19_49 + 170;
  total = total.1_20;

because we do not constant-fold vector shifts.  Two ways to attack the
problem (SCCP failure needs to be analyzed).  In 4.7 SCCP works.


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

* [Bug tree-optimization/57051] [4.8/4.9 Regression] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
  2013-04-24  8:10 ` [Bug tree-optimization/57051] " mpolacek at gcc dot gnu.org
  2013-04-24  8:30 ` [Bug tree-optimization/57051] [4.8/4.9 Regression] " rguenth at gcc dot gnu.org
@ 2013-04-24 10:44 ` jakub at gcc dot gnu.org
  2013-04-26 13:17 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-24 10:44 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-24 10:44:13 UTC ---
Created attachment 29928
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29928
gcc49-pr57051.patch

It isn't that hard to fold VEC_RSHIFT_EXPR, at least for the cases where the
shift count is a multiple of element bitsize (the only case where GCC actually
ever emits VEC_RSHIFT_EXPR right now).

Untested (beyond checking this is folded into store of 450 again).


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

* [Bug tree-optimization/57051] [4.8/4.9 Regression] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
                   ` (2 preceding siblings ...)
  2013-04-24 10:44 ` jakub at gcc dot gnu.org
@ 2013-04-26 13:17 ` jakub at gcc dot gnu.org
  2013-05-03 13:57 ` [Bug tree-optimization/57051] [4.8 " jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-26 13:17 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-26 13:16:58 UTC ---
Author: jakub
Date: Fri Apr 26 13:13:36 2013
New Revision: 198339

URL: http://gcc.gnu.org/viewcvs?rev=198339&root=gcc&view=rev
Log:
    PR tree-optimization/57051
    * fold-const.c (const_binop): Handle VEC_LSHIFT_EXPR
    and VEC_RSHIFT_EXPR if shift count is a multiple of element
    bitsize.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c


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

* [Bug tree-optimization/57051] [4.8 Regression] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
                   ` (3 preceding siblings ...)
  2013-04-26 13:17 ` jakub at gcc dot gnu.org
@ 2013-05-03 13:57 ` jakub at gcc dot gnu.org
  2013-05-03 14:00 ` [Bug tree-optimization/57051] " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-03 13:57 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-05-03 13:57:52 UTC ---
Author: jakub
Date: Fri May  3 13:16:13 2013
New Revision: 198580

URL: http://gcc.gnu.org/viewcvs?rev=198580&root=gcc&view=rev
Log:
    Backported from mainline
    2013-04-26  Jakub Jelinek  <jakub@redhat.com>

    PR tree-optimization/57051
    * fold-const.c (const_binop): Handle VEC_LSHIFT_EXPR
    and VEC_RSHIFT_EXPR if shift count is a multiple of element
    bitsize.

    2013-04-12  Marc Glisse  <marc.glisse@inria.fr>

    * fold-const.c (fold_binary_loc): Call const_binop also for mixed
    vector-scalar operations.

Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/fold-const.c

The testcase should now no longer regress, keeping open for Richard's SCEV
investigation.


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

* [Bug tree-optimization/57051] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
                   ` (4 preceding siblings ...)
  2013-05-03 13:57 ` [Bug tree-optimization/57051] [4.8 " jakub at gcc dot gnu.org
@ 2013-05-03 14:00 ` jakub at gcc dot gnu.org
  2013-05-06 11:55 ` rguenth at gcc dot gnu.org
  2013-05-17 12:27 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-03 14:00 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.8.1                       |---
            Summary|[4.8 Regression]            |Optimization regression in
                   |Optimization regression in  |4.8.0 from 4.7.2
                   |4.8.0 from 4.7.2            |


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

* [Bug tree-optimization/57051] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
                   ` (5 preceding siblings ...)
  2013-05-03 14:00 ` [Bug tree-optimization/57051] " jakub at gcc dot gnu.org
@ 2013-05-06 11:55 ` rguenth at gcc dot gnu.org
  2013-05-17 12:27 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-06 11:55 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> 2013-05-06 11:54:55 UTC ---
Mine.


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

* [Bug tree-optimization/57051] Optimization regression in 4.8.0 from 4.7.2
  2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
                   ` (6 preceding siblings ...)
  2013-05-06 11:55 ` rguenth at gcc dot gnu.org
@ 2013-05-17 12:27 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-17 12:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri May 17 08:31:32 2013
New Revision: 199002

URL: http://gcc.gnu.org/viewcvs?rev=199002&root=gcc&view=rev
Log:
    PR tree-optimization/57051
    * fold-const.c (const_binop) <case VEC_LSHIFT_EXPR,
    case VEC_RSHIFT_EXPR>: Fix BYTES_BIG_ENDIAN handling.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c

Author: jakub
Date: Fri May 17 08:52:36 2013
New Revision: 199004

URL: http://gcc.gnu.org/viewcvs?rev=199004&root=gcc&view=rev
Log:
    PR tree-optimization/57051
    * fold-const.c (const_binop) <case VEC_LSHIFT_EXPR,
    case VEC_RSHIFT_EXPR>: Fix BYTES_BIG_ENDIAN handling.

Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/fold-const.c


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

end of thread, other threads:[~2013-05-17 12:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-23 16:25 [Bug c/57051] New: Optimization regression in 4.8.0 from 4.7.2 tony.howard-co84udjx at yopmail dot com
2013-04-24  8:10 ` [Bug tree-optimization/57051] " mpolacek at gcc dot gnu.org
2013-04-24  8:30 ` [Bug tree-optimization/57051] [4.8/4.9 Regression] " rguenth at gcc dot gnu.org
2013-04-24 10:44 ` jakub at gcc dot gnu.org
2013-04-26 13:17 ` jakub at gcc dot gnu.org
2013-05-03 13:57 ` [Bug tree-optimization/57051] [4.8 " jakub at gcc dot gnu.org
2013-05-03 14:00 ` [Bug tree-optimization/57051] " jakub at gcc dot gnu.org
2013-05-06 11:55 ` rguenth at gcc dot gnu.org
2013-05-17 12:27 ` jakub at gcc dot gnu.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).