public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/56918] New: incorrect auto-vectorization of array initialization
@ 2013-04-11 11:04 kretz at kde dot org
  2013-04-11 11:42 ` [Bug tree-optimization/56918] [4.8 Regression] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kretz at kde dot org @ 2013-04-11 11:04 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56918
           Summary: incorrect auto-vectorization of array initialization
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kretz@kde.org


Compile the following testcase with "gcc -m32 -O2 -ftree-vectorize -msse2"

int main() {
    double data[4];
    for (int i = 0; i < 2 * 2; ++i) {
        data[i] = ((i + 2) % 3) + 1;
    }
    if (data[0] != 3.) {
        return 1;
    }
    return 0;
}

The first for-loop calculates the values 6, 7, 8, 9 instead of the expected 3,
1, 2, 3.


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

* [Bug tree-optimization/56918] [4.8 Regression] incorrect auto-vectorization of array initialization
  2013-04-11 11:04 [Bug tree-optimization/56918] New: incorrect auto-vectorization of array initialization kretz at kde dot org
@ 2013-04-11 11:42 ` rguenth at gcc dot gnu.org
  2013-04-11 11:59 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-04-11 11:42 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-04-11
      Known to work|                            |4.9.0
   Target Milestone|---                         |4.8.1
            Summary|incorrect                   |[4.8 Regression] incorrect
                   |auto-vectorization of array |auto-vectorization of array
                   |initialization              |initialization
     Ever Confirmed|0                           |1
      Known to fail|                            |4.8.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> 2013-04-11 11:42:49 UTC ---
extern void abort (void);
double data[4];
int main()
{
  int i;
  for (i = 0; i < 2 * 2; ++i)
    data[i] = ((i + 2) % 3) + 1;
  if (data[0] != 3)
    abort ();
  return 0;
}

Seems to work on trunk.


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

* [Bug tree-optimization/56918] [4.8 Regression] incorrect auto-vectorization of array initialization
  2013-04-11 11:04 [Bug tree-optimization/56918] New: incorrect auto-vectorization of array initialization kretz at kde dot org
  2013-04-11 11:42 ` [Bug tree-optimization/56918] [4.8 Regression] " rguenth at gcc dot gnu.org
@ 2013-04-11 11:59 ` rguenth at gcc dot gnu.org
  2013-04-11 14:43 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-04-11 11:59 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> 2013-04-11 11:59:05 UTC ---
The vectorizer does nothing wrong.  The bug goes away with -fdisable-tree-vrp2
which would expose

-  stmp_var_.3_2 = 0 + 1;
-  stmp_var_.3_19 = stmp_var_.3_2 + 1;
-  stmp_var_.3_20 = stmp_var_.3_19 + 1;
-  vect_cst_.4_21 = {0, stmp_var_.3_2, stmp_var_.3_19, stmp_var_.3_20};
+  stmp_var_.3_2 = 1;
+  stmp_var_.3_19 = 2;
+  stmp_var_.3_20 = 3;
+  vect_cst_.4_21 = { 0, 1, 2, 3 };

(ick, unfolded 0 + 1)

so we expand

  vect_patt.11_29 = { 2, 3, 4, 5 } >> 31;
  vect_patt.12_30 = { -1, -1, -1, -1 } - vect_patt.11_29;
  vect_patt.13_32 = vect_patt.12_30 * { 3, 3, 3, 3 };
  vect_patt.15_33 = { 2, 3, 4, 5 } - vect_patt.13_32;
  vect_var_.16_35 = vect_patt.15_33 + { 1, 1, 1, 1 };
  vect_var_.18_36 = [vec_unpack_float_lo_expr] vect_var_.16_35;
  vect_var_.18_37 = [vec_unpack_float_hi_expr] vect_var_.16_35;
  MEM[(double[1024] *)&data] = vect_var_.18_36;
  MEM[(double[1024] *)&data + 16B] = vect_var_.18_37;
  _10 = data[0];
  if (_10 != 3.0e+0)

where I bet that unfolded constant expressions are somehow mis-handled.


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

* [Bug tree-optimization/56918] [4.8 Regression] incorrect auto-vectorization of array initialization
  2013-04-11 11:04 [Bug tree-optimization/56918] New: incorrect auto-vectorization of array initialization kretz at kde dot org
  2013-04-11 11:42 ` [Bug tree-optimization/56918] [4.8 Regression] " rguenth at gcc dot gnu.org
  2013-04-11 11:59 ` rguenth at gcc dot gnu.org
@ 2013-04-11 14:43 ` jakub at gcc dot gnu.org
  2013-04-11 15:20 ` jakub at gcc dot gnu.org
  2013-04-12  9:13 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-11 14:43 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |jakub at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-11 14:43:30 UTC ---
Created attachment 29858
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29858
gcc49-pr56918.patch

Untested fix.


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

* [Bug tree-optimization/56918] [4.8 Regression] incorrect auto-vectorization of array initialization
  2013-04-11 11:04 [Bug tree-optimization/56918] New: incorrect auto-vectorization of array initialization kretz at kde dot org
                   ` (2 preceding siblings ...)
  2013-04-11 14:43 ` jakub at gcc dot gnu.org
@ 2013-04-11 15:20 ` jakub at gcc dot gnu.org
  2013-04-12  9:13 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-11 15:20 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-11 15:20:11 UTC ---
*** Bug 56920 has been marked as a duplicate of this bug. ***


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

* [Bug tree-optimization/56918] [4.8 Regression] incorrect auto-vectorization of array initialization
  2013-04-11 11:04 [Bug tree-optimization/56918] New: incorrect auto-vectorization of array initialization kretz at kde dot org
                   ` (3 preceding siblings ...)
  2013-04-11 15:20 ` jakub at gcc dot gnu.org
@ 2013-04-12  9:13 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-12  9:13 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-12 09:13:24 UTC ---
Author: jakub
Date: Fri Apr 12 08:18:59 2013
New Revision: 197846

URL: http://gcc.gnu.org/viewcvs?rev=197846&root=gcc&view=rev
Log:
    PR tree-optimization/56918
    PR tree-optimization/56920
    * fold-const.c (int_const_binop_1): Use op1.mul_with_sign (op2, ...)
    instead of op1 - op2.  Pass 2 * TYPE_PRECISION (type) as second
    argument to rshift method.  For 2 * HOST_BITS_PER_WIDE_INT precision
    use wide_mul_with_sign method.

    * gcc.dg/vect/pr56918.c: New test.
    * gcc.dg/vect/pr56920.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr56918.c
    trunk/gcc/testsuite/gcc.dg/vect/pr56920.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Author: jakub
Date: Fri Apr 12 08:38:29 2013
New Revision: 197847

URL: http://gcc.gnu.org/viewcvs?rev=197847&root=gcc&view=rev
Log:
    PR tree-optimization/56918
    PR tree-optimization/56920
    * fold-const.c (int_const_binop_1): Use op1.mul_with_sign (op2, ...)
    instead of op1 - op2.  Pass 2 * TYPE_PRECISION (type) as second
    argument to rshift method.

    * gcc.dg/vect/pr56918.c: New test.
    * gcc.dg/vect/pr56920.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/vect/pr56918.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/vect/pr56920.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/fold-const.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2013-04-12  9:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-11 11:04 [Bug tree-optimization/56918] New: incorrect auto-vectorization of array initialization kretz at kde dot org
2013-04-11 11:42 ` [Bug tree-optimization/56918] [4.8 Regression] " rguenth at gcc dot gnu.org
2013-04-11 11:59 ` rguenth at gcc dot gnu.org
2013-04-11 14:43 ` jakub at gcc dot gnu.org
2013-04-11 15:20 ` jakub at gcc dot gnu.org
2013-04-12  9:13 ` 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).