public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
@ 2014-09-05 14:28 brett@mynah-software.com
  2014-09-05 14:53 ` [Bug c/63189] [4.8 Regression] " glisse at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: brett@mynah-software.com @ 2014-09-05 14:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

            Bug ID: 63189
           Summary: Incorrect results from trivial loop when optimized
                    with O3 or O2+tree vectorization
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: brett@mynah-software.com

The following code runs two identical loops with the exception that one
variable is marked as volatile:

#include <stdio.h>

short int srcdata[16] = { 0, 0, 0, 0, 0, 0, 0, 1,0,0,0,0,0,0,0,0 };

int main(int argc, char **argv)
{
  int hix= 8;
  int j;
  volatile int  s1ref = 0;
  for(j = 0; j < hix; j++){ s1ref += srcdata[j]*j;}
  int s1=0;
  for(j = 0; j < hix; j++) { s1 += srcdata[j]*j;}
  printf("s1ref=%d, s1=%d\n",s1ref,s1);
}

I would expect the results to be identical for s1ref and s1 under all
compilation options, however when compiling with O3 or O2 with
-ftree-vectorization I get incorrect results for S1:

bms20@arthas:/tmp$ gcc -O2 test.c && ./a.out
s1ref=7, s1=7
bms20@arthas:/tmp$ gcc -O3 test.c && ./a.out
s1ref=7, s1=1
bms20@arthas:/tmp$ gcc -O2 -ftree-vectorize test.c && ./a.out
s1ref=7, s1=1
bms20@arthas:/tmp$

Changing the type of srcdata to integers or unsigned shorts appears to fix the
problem; however, this is producing incorrect results with signed shorts.

It appears that the vector code is incorrect from examining the .s files
produced.


SETUP SPECIFICS:

Exact version of GCC:

bms20@arthas:/tmp$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,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 --disable-libmudflap
--enable-plugin --with-system-zlib --disable-browser-plugin
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 


System type:

Ubuntu Linux 14.04 running on x86_64.


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

* [Bug c/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
@ 2014-09-05 14:53 ` glisse at gcc dot gnu.org
  2014-09-05 15:56 ` brett@mynah-software.com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-09-05 14:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-09-05
            Summary|Incorrect results from      |[4.8 Regression] Incorrect
                   |trivial loop when optimized |results from trivial loop
                   |with O3 or O2+tree          |when optimized with O3 or
                   |vectorization               |O2+tree vectorization
     Ever confirmed|0                           |1

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
Seems fine with 4.6, 4.7, 4.9 and 5, only 4.8 fails.


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

* [Bug c/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
  2014-09-05 14:53 ` [Bug c/63189] [4.8 Regression] " glisse at gcc dot gnu.org
@ 2014-09-05 15:56 ` brett@mynah-software.com
  2014-09-06 11:40 ` mikpelinux at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: brett@mynah-software.com @ 2014-09-05 15:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

--- Comment #2 from Breton M. Saunders <brett@mynah-software.com> ---
I'm actually showing the same symptoms on Ubuntu 12.04 using virtual-box and
gcc v4.6.3.

Here are the details:

bms20@medivh-lbo-vm:~/LboPlatforms/ti37XX$ uname -a
Linux medivh-lbo-vm 3.8.0-44-generic #66~precise1-Ubuntu SMP Tue Jul 15
04:01:04 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
bms20@medivh-lbo-vm:~/LboPlatforms/ti37XX$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --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.6
--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-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 



And a cut-and-paste of the run:

bms20@medivh-lbo-vm:/tmp$ gcc -O2 test.c && ./a.out
s1ref=7, s1=7
bms20@medivh-lbo-vm:/tmp$ gcc -O2 -ftree-vectorize test.c && ./a.out
s1ref=7, s1=1
bms20@medivh-lbo-vm:/tmp$ gcc -O3 test.c && ./a.out
s1ref=7, s1=1
bms20@medivh-lbo-vm:/tmp$


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

* [Bug c/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
  2014-09-05 14:53 ` [Bug c/63189] [4.8 Regression] " glisse at gcc dot gnu.org
  2014-09-05 15:56 ` brett@mynah-software.com
@ 2014-09-06 11:40 ` mikpelinux at gmail dot com
  2014-09-08  9:04 ` [Bug tree-optimization/63189] " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mikpelinux at gmail dot com @ 2014-09-06 11:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

Mikael Pettersson <mikpelinux at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikpelinux at gmail dot com

--- Comment #3 from Mikael Pettersson <mikpelinux at gmail dot com> ---
I can reproduce the wrong-code with current 4.8, but not with 4.7.4 or 4.6.4
(all unmodified FSF versions).  The bug in 4.8 gets fixed by backporting
r202663, which also fixes PR60196.  The three test cases are essentially
identical.


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

* [Bug tree-optimization/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
                   ` (2 preceding siblings ...)
  2014-09-06 11:40 ` mikpelinux at gmail dot com
@ 2014-09-08  9:04 ` rguenth at gcc dot gnu.org
  2014-09-08 20:08 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-09-08  9:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |congh at gcc dot gnu.org
   Target Milestone|---                         |4.8.4


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

* [Bug tree-optimization/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
                   ` (3 preceding siblings ...)
  2014-09-08  9:04 ` [Bug tree-optimization/63189] " rguenth at gcc dot gnu.org
@ 2014-09-08 20:08 ` jakub at gcc dot gnu.org
  2014-09-08 20:16 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-09-08 20:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Mon Sep  8 20:07:29 2014
New Revision: 215024

URL: https://gcc.gnu.org/viewcvs?rev=215024&root=gcc&view=rev
Log:
    PR tree-optimization/60196
    PR tree-optimization/63189
    Backported from mainline
    2013-09-17  Cong Hou  <congh@google.com>

    * tree-vect-patterns.c (vect_recog_dot_prod_pattern): Fix a bug
    when checking the dot production pattern. The type of rhs operand
    of multiply is now checked correctly.

    * gcc.dg/vect/pr63189.c: New test.
    * gcc.dg/vect/pr60196-1.c: New test.
    * gcc.dg/vect/pr60196-2.c: New test.

    Backported from mainline
    2013-09-17  Cong Hou  <congh@google.com>

    * gcc.dg/vect/vect-reduc-dot-s16c.c: Add a test case with dot product 
    on two arrays with short and int types. This should not be recognized
    as a dot product pattern.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/vect/pr60196-1.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/vect/pr60196-2.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/vect/pr63189.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-vect-patterns.c


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

* [Bug tree-optimization/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
                   ` (4 preceding siblings ...)
  2014-09-08 20:08 ` jakub at gcc dot gnu.org
@ 2014-09-08 20:16 ` jakub at gcc dot gnu.org
  2014-09-08 20:18 ` jakub at gcc dot gnu.org
  2014-09-08 20:18 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-09-08 20:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Mon Sep  8 20:15:31 2014
New Revision: 215025

URL: https://gcc.gnu.org/viewcvs?rev=215025&root=gcc&view=rev
Log:
    PR tree-optimization/60196
    PR tree-optimization/63189
    * gcc.dg/vect/pr63189.c: New test.
    * gcc.dg/vect/pr60196-1.c: New test.
    * gcc.dg/vect/pr60196-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr60196-1.c
    trunk/gcc/testsuite/gcc.dg/vect/pr60196-2.c
    trunk/gcc/testsuite/gcc.dg/vect/pr63189.c
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug tree-optimization/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
                   ` (5 preceding siblings ...)
  2014-09-08 20:16 ` jakub at gcc dot gnu.org
@ 2014-09-08 20:18 ` jakub at gcc dot gnu.org
  2014-09-08 20:18 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-09-08 20:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Mon Sep  8 20:18:02 2014
New Revision: 215026

URL: https://gcc.gnu.org/viewcvs?rev=215026&root=gcc&view=rev
Log:
    PR tree-optimization/60196
    PR tree-optimization/63189
    * gcc.dg/vect/pr63189.c: New test.
    * gcc.dg/vect/pr60196-1.c: New test.
    * gcc.dg/vect/pr60196-2.c: New test.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/vect/pr60196-1.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/vect/pr60196-2.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/vect/pr63189.c
Modified:
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog


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

* [Bug tree-optimization/63189] [4.8 Regression] Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization
  2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
                   ` (6 preceding siblings ...)
  2014-09-08 20:18 ` jakub at gcc dot gnu.org
@ 2014-09-08 20:18 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-09-08 20:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63189

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.


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

end of thread, other threads:[~2014-09-08 20:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-05 14:28 [Bug c/63189] New: Incorrect results from trivial loop when optimized with O3 or O2+tree vectorization brett@mynah-software.com
2014-09-05 14:53 ` [Bug c/63189] [4.8 Regression] " glisse at gcc dot gnu.org
2014-09-05 15:56 ` brett@mynah-software.com
2014-09-06 11:40 ` mikpelinux at gmail dot com
2014-09-08  9:04 ` [Bug tree-optimization/63189] " rguenth at gcc dot gnu.org
2014-09-08 20:08 ` jakub at gcc dot gnu.org
2014-09-08 20:16 ` jakub at gcc dot gnu.org
2014-09-08 20:18 ` jakub at gcc dot gnu.org
2014-09-08 20:18 ` 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).