public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/29925]  New: Wrong code with -ftree-vectorize
@ 2006-11-21 12:22 jean-marc dot valin at usherbrooke dot ca
  2006-11-21 12:24 ` [Bug c/29925] " jean-marc dot valin at usherbrooke dot ca
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: jean-marc dot valin at usherbrooke dot ca @ 2006-11-21 12:22 UTC (permalink / raw)
  To: gcc-bugs

I just hit what seems to be a wrong code generation bug in gcc. The bug happens
only when compiling the attached file with:
gcc -g -O1 -ffast-math -ftree-vectorize gcc_bug.c -o gcc_bug

Removing any one of -O1 -ffast-math -ftree-vectorize makes the problem go away.
When I run the complete code (which is in the Speex codec BTW), not only do I
get the wrong result, but there is a "read past array" that happens. With the
reduced example, only the read error is visible and valgrind reports:

==9508== Invalid read of size 8
==9508==    at 0x4004E3: interp_pitch (gcc_bug.c:17)
==9508==    by 0x4005D2: main (gcc_bug.c:29)
==9508==  Address 0x4D64224 is 500 bytes inside a block of size 504 alloc'd
==9508==    at 0x4A1FB37: calloc (vg_replace_malloc.c:279)
==9508==    by 0x4005A8: main (gcc_bug.c:25)

This is on an Ubuntu 64-bit Edgy machine with gcc -v:

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release
x86_64-linux-gnu
Thread model: posix
gcc version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


-- 
           Summary: Wrong code with -ftree-vectorize
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jean-marc dot valin at usherbrooke dot ca


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


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

* [Bug c/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
@ 2006-11-21 12:24 ` jean-marc dot valin at usherbrooke dot ca
  2006-11-21 12:30 ` jean-marc dot valin at usherbrooke dot ca
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jean-marc dot valin at usherbrooke dot ca @ 2006-11-21 12:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jean-marc dot valin at usherbrooke dot ca  2006-11-21 12:23 -------
Created an attachment (id=12658)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12658&action=view)
C file that reproduces the problem

Compile with:
gcc -g -O1 -ffast-math -ftree-vectorize gcc_bug.c -o gcc_bug
to reproduce the problem and run under valgrind.


-- 


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


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

* [Bug c/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
  2006-11-21 12:24 ` [Bug c/29925] " jean-marc dot valin at usherbrooke dot ca
@ 2006-11-21 12:30 ` jean-marc dot valin at usherbrooke dot ca
  2006-11-21 12:32 ` jean-marc dot valin at usherbrooke dot ca
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jean-marc dot valin at usherbrooke dot ca @ 2006-11-21 12:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jean-marc dot valin at usherbrooke dot ca  2006-11-21 12:30 -------
Created an attachment (id=12659)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12659&action=view)
Wrong assembly generated

This is the result of:
gcc -O1 -ffast-math -ftree-vectorize -S gcc_bug.c
which generates wrong code.


-- 


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


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

* [Bug c/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
  2006-11-21 12:24 ` [Bug c/29925] " jean-marc dot valin at usherbrooke dot ca
  2006-11-21 12:30 ` jean-marc dot valin at usherbrooke dot ca
@ 2006-11-21 12:32 ` jean-marc dot valin at usherbrooke dot ca
  2006-11-21 12:35 ` rguenth at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jean-marc dot valin at usherbrooke dot ca @ 2006-11-21 12:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jean-marc dot valin at usherbrooke dot ca  2006-11-21 12:32 -------
Created an attachment (id=12660)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12660&action=view)
Correct (non-vectorized) code

This is the code generated with:
gcc -O1 -ffast-math -S gcc_bug.c
and works correctly.


-- 


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


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

* [Bug c/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (2 preceding siblings ...)
  2006-11-21 12:32 ` jean-marc dot valin at usherbrooke dot ca
@ 2006-11-21 12:35 ` rguenth at gcc dot gnu dot org
  2006-11-21 14:29 ` [Bug tree-optimization/29925] " jean-marc dot valin at usherbrooke dot ca
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-11-21 12:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2006-11-21 12:34 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.1.2
      Known to work|                            |4.3.0
   Last reconfirmed|0000-00-00 00:00:00         |2006-11-21 12:34:43
               date|                            |


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (3 preceding siblings ...)
  2006-11-21 12:35 ` rguenth at gcc dot gnu dot org
@ 2006-11-21 14:29 ` jean-marc dot valin at usherbrooke dot ca
  2006-12-14 12:42 ` irar at il dot ibm dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jean-marc dot valin at usherbrooke dot ca @ 2006-11-21 14:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jean-marc dot valin at usherbrooke dot ca  2006-11-21 14:29 -------
Some additional info. valgrind reports that the read includes 4 bytes (out of
8) outside of the array, but in fact given the inputs, it shouldn't even read
that close to the array bound in the first place. So the address computation is
completely wrong. Also, strange is that simply replacing maxj by its value (3)
in:
tmp += exc[i-pitch+k+maxj-6];
makes the problem disappear.


-- 


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (4 preceding siblings ...)
  2006-11-21 14:29 ` [Bug tree-optimization/29925] " jean-marc dot valin at usherbrooke dot ca
@ 2006-12-14 12:42 ` irar at il dot ibm dot com
  2006-12-14 13:28 ` jean-marc dot valin at usherbrooke dot ca
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: irar at il dot ibm dot com @ 2006-12-14 12:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from irar at il dot ibm dot com  2006-12-14 12:41 -------
I couldn't reproduce the problem on x86. I ran it with valgrind
--leak-check=yes, is it correct?

Ira


-- 


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (5 preceding siblings ...)
  2006-12-14 12:42 ` irar at il dot ibm dot com
@ 2006-12-14 13:28 ` jean-marc dot valin at usherbrooke dot ca
  2006-12-30  6:42 ` jean-marc dot valin at usherbrooke dot ca
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jean-marc dot valin at usherbrooke dot ca @ 2006-12-14 13:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jean-marc dot valin at usherbrooke dot ca  2006-12-14 13:28 -------
Could be x86-64 only, I don't know. I don't have a plain x86 with gcc 4.1 to
test on.


-- 


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (6 preceding siblings ...)
  2006-12-14 13:28 ` jean-marc dot valin at usherbrooke dot ca
@ 2006-12-30  6:42 ` jean-marc dot valin at usherbrooke dot ca
  2007-03-05  8:01 ` patchapp at dberlin dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jean-marc dot valin at usherbrooke dot ca @ 2006-12-30  6:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jean-marc dot valin at usherbrooke dot ca  2006-12-30 06:42 -------
Shouldn't the priority of this bug be increased considering that it produces
wrong code on valid input and the affected package (Speex) is included in most
Linux distributions (fortunately most of these don't enable -ftree-vectorize by
default I think)?


-- 


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (7 preceding siblings ...)
  2006-12-30  6:42 ` jean-marc dot valin at usherbrooke dot ca
@ 2007-03-05  8:01 ` patchapp at dberlin dot org
  2007-03-11 13:47 ` irar at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: patchapp at dberlin dot org @ 2007-03-05  8:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from patchapp at dberlin dot org  2007-03-05 08:01 -------
Subject: Bug number PR tree-optimization/29925

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00254.html


-- 


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (8 preceding siblings ...)
  2007-03-05  8:01 ` patchapp at dberlin dot org
@ 2007-03-11 13:47 ` irar at gcc dot gnu dot org
  2007-03-12  6:57 ` irar at gcc dot gnu dot org
  2007-07-01  8:35 ` dorit at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: irar at gcc dot gnu dot org @ 2007-03-11 13:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from irar at gcc dot gnu dot org  2007-03-11 13:47 -------
Subject: Bug 29925

Author: irar
Date: Sun Mar 11 13:47:40 2007
New Revision: 122819

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122819
Log:
        PR tree-optimization/29925
        * tree-data-ref.c (analyze_offset): Add a return value (bool) to
        indicate success/failure of the analysis. Add negation to subtrahend
        in case of subtraction. Fail if both operands contain constants.
        (create_data_ref): Fail if analyze_offset fails.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/vect/fast-math-vect-pr29925.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/gcc/tree-data-ref.c


-- 


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (9 preceding siblings ...)
  2007-03-11 13:47 ` irar at gcc dot gnu dot org
@ 2007-03-12  6:57 ` irar at gcc dot gnu dot org
  2007-07-01  8:35 ` dorit at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: irar at gcc dot gnu dot org @ 2007-03-12  6:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from irar at gcc dot gnu dot org  2007-03-12 06:56 -------
Subject: Bug 29925

Author: irar
Date: Mon Mar 12 06:56:41 2007
New Revision: 122833

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122833
Log:
        PR tree-optimization/29925
        * tree-data-ref.c (analyze_offset): Add a return value (bool) to
        indicate success/failure of the analysis. Add negation to subtrahend
        in case of subtraction. Fail if both operands contain constants.
        (create_data_ref): Fail if analyze_offset fails.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/vect/fast-math-vect-pr29925.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/tree-data-ref.c


-- 


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


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

* [Bug tree-optimization/29925] Wrong code with -ftree-vectorize
  2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
                   ` (10 preceding siblings ...)
  2007-03-12  6:57 ` irar at gcc dot gnu dot org
@ 2007-07-01  8:35 ` dorit at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: dorit at gcc dot gnu dot org @ 2007-07-01  8:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from dorit at gcc dot gnu dot org  2007-07-01 08:35 -------
A fix was committed, looks like the patch can be closed.


-- 

dorit at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2007-07-01  8:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-21 12:22 [Bug c/29925] New: Wrong code with -ftree-vectorize jean-marc dot valin at usherbrooke dot ca
2006-11-21 12:24 ` [Bug c/29925] " jean-marc dot valin at usherbrooke dot ca
2006-11-21 12:30 ` jean-marc dot valin at usherbrooke dot ca
2006-11-21 12:32 ` jean-marc dot valin at usherbrooke dot ca
2006-11-21 12:35 ` rguenth at gcc dot gnu dot org
2006-11-21 14:29 ` [Bug tree-optimization/29925] " jean-marc dot valin at usherbrooke dot ca
2006-12-14 12:42 ` irar at il dot ibm dot com
2006-12-14 13:28 ` jean-marc dot valin at usherbrooke dot ca
2006-12-30  6:42 ` jean-marc dot valin at usherbrooke dot ca
2007-03-05  8:01 ` patchapp at dberlin dot org
2007-03-11 13:47 ` irar at gcc dot gnu dot org
2007-03-12  6:57 ` irar at gcc dot gnu dot org
2007-07-01  8:35 ` dorit 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).