public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3
@ 2014-07-27 16:55 krefson at gmail dot com
  2014-07-27 16:56 ` [Bug fortran/61927] " krefson at gmail dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: krefson at gmail dot com @ 2014-07-27 16:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61927
           Summary: Optimization bug (regression): Array comparison yields
                    unassigned result at -O3
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: krefson at gmail dot com

The attached code, which tests an allocatable array for nonzero values, works
correctly when compiled at -O1 and -O3, but malfunctions at -O3.

$ gfortran -O2  arrayop2.f90
$ ./a.out
Symm_Nonzero
    T    F    F    F    T    F    F    F    T   3
    T    F    F    F    T    F    F    F    T   3
    T    F    F    F    F    T    F    T    F   3
    T    F    F    F    F    T    F    T    F   3
    T    F    F    F    T    F    F    F    T   3
    T    F    F    F    T    F    F    F    T   3
    T    F    F    F    F    T    F    T    F   3
    T    F    F    F    F    T    F    T    F   3
$ ./a.out
Symm_Nonzero
    T    F    F    F    T    F    F    F    T   3
    F    F    F    T    T    F    F    T    T   4
    T    T    T    F    T    T    F    F    T****
    T    F    F    T    F    T    T    F    F****
    F    F    T    T    F    F    T    T    T   5
    T    T    T    T    T    F    F    T    T****
    T    T    T    T    F    F    T    T    T****
    T    T    F    T    T    T    T    T    T****

Running under valgrind reveals that some elements of the result array
"symm_nonzero" contain uninitialized data in the -O3 case.

This is a regression in 4.9.1.  The code works correctly at -O3 under 4.8,2


uname -a
Linux gibbs 3.12.21-desktop-2.mga4 #1 SMP Thu Jun 5 21:33:44 UTC 2014 x86_64
x86_64 x86_64 GNU/Linux

$ gfortran --version
GNU Fortran (GCC) 4.9.1 20140709 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.


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

* [Bug fortran/61927] Optimization bug (regression): Array comparison yields unassigned result at -O3
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
@ 2014-07-27 16:56 ` krefson at gmail dot com
  2014-07-27 21:30 ` [Bug middle-end/61927] [4.9/4.10 Regression] Optimization bug: " burnus at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: krefson at gmail dot com @ 2014-07-27 16:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Keith Refson <krefson at gmail dot com> ---
Created attachment 33193
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33193&action=edit
Testcase for array comparison optimization bug


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

* [Bug middle-end/61927] [4.9/4.10 Regression] Optimization bug: Array comparison yields unassigned result at -O3
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
  2014-07-27 16:56 ` [Bug fortran/61927] " krefson at gmail dot com
@ 2014-07-27 21:30 ` burnus at gcc dot gnu.org
  2014-08-11 10:01 ` [Bug middle-end/61927] [4.9/4.10 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]> > 9.9e-7" jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2014-07-27 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |burnus at gcc dot gnu.org
          Component|fortran                     |middle-end
   Target Milestone|---                         |4.9.2
            Summary|Optimization bug            |[4.9/4.10 Regression]
                   |(regression): Array         |Optimization bug: Array
                   |comparison yields           |comparison yields
                   |unassigned result at -O3    |unassigned result at -O3

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Confirmed on x86-64-gnu-linux with GCC 4.10/5; it fails with -O3 but works with
-O3 -fno-vectorize.


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

* [Bug middle-end/61927] [4.9/4.10 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
  2014-07-27 16:56 ` [Bug fortran/61927] " krefson at gmail dot com
  2014-07-27 21:30 ` [Bug middle-end/61927] [4.9/4.10 Regression] Optimization bug: " burnus at gcc dot gnu.org
@ 2014-08-11 10:01 ` jakub at gcc dot gnu.org
  2014-10-30 10:41 ` [Bug middle-end/61927] [4.9/5 " jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-08-11 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-08-11
                 CC|                            |jakub at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I see result differences and valgrind errors starting with r167220 , then
r183757 fixed that (all options).
Then r196872 regressed this again for the vectorizer.


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

* [Bug middle-end/61927] [4.9/5 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (2 preceding siblings ...)
  2014-08-11 10:01 ` [Bug middle-end/61927] [4.9/4.10 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]> > 9.9e-7" jakub at gcc dot gnu.org
@ 2014-10-30 10:41 ` jakub at gcc dot gnu.org
  2014-11-24 13:03 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-30 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.2                       |4.9.3

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.2 has been released.


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

* [Bug middle-end/61927] [4.9/5 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (3 preceding siblings ...)
  2014-10-30 10:41 ` [Bug middle-end/61927] [4.9/5 " jakub at gcc dot gnu.org
@ 2014-11-24 13:03 ` rguenth at gcc dot gnu.org
  2014-11-25 10:53 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-24 13:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look.


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

* [Bug middle-end/61927] [4.9/5 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (4 preceding siblings ...)
  2014-11-24 13:03 ` rguenth at gcc dot gnu.org
@ 2014-11-25 10:53 ` rguenth at gcc dot gnu.org
  2014-11-25 11:07 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-25 10:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, we store

  MEM[(logical(kind=4) *)_227] = vect_patt_319.44_273;
...
  MEM[(logical(kind=4) *)_227 + 4B] = vect_patt_318.52_169;
...
  MEM[(logical(kind=4) *)_227 + 8B] = vect_patt_304.60_132;
...

the result vectors 4 bytes apart but the vectors are 16byte V4SI ones.

So we unroll the inner two loops and get

  for (i = 1; i <= 8; ++i)
    {
      symm_nonzero[i][0][0] = ABS ... > ...;
      ... repeated 9 times with other constant 2nd/3rd index ...
    }

which we vectorize to a loop with two iterations but still 9 vector stores
to symm_nonzero.  This doesn't make much sense...  it looks like SLP
failed half-way.  Or rather the vectorizer is somehow confused by
the bool pattern detected:

t.f90:42:0: note: pattern recognized: VIEW_CONVERT_EXPR<unsigned
int>(symm_nonzero[_200]) = patt_319;

with the VIEW_CONVERT_EXPR on the LHS which is not seen as grouped store.

So it looks like vect_recog_bool_pattern does not handle grouped stores
properly and

Index: tree-vect-patterns.c
===================================================================
--- tree-vect-patterns.c        (revision 218019)
+++ tree-vect-patterns.c        (working copy)
@@ -3261,6 +3261,8 @@ vect_recog_bool_pattern (vec<gimple> *st
       gcc_assert (vectype != NULL_TREE);
       if (!VECTOR_MODE_P (TYPE_MODE (vectype)))
        return NULL;
+      if (STMT_VINFO_GROUP_FIRST_ELEMENT (stmt_vinfo))
+       return NULL;
       if (!check_bool_pattern (var, loop_vinfo, bb_vinfo))
        return NULL;

fixes this testcase (and then does not vectorize this loop).

Any takers making this testcase suitable for the testsuite?  It should
abort() for bogus results and return normally for success.  It should
not output to the terminal.


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

* [Bug middle-end/61927] [4.9/5 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (5 preceding siblings ...)
  2014-11-25 10:53 ` rguenth at gcc dot gnu.org
@ 2014-11-25 11:07 ` rguenth at gcc dot gnu.org
  2014-11-25 14:56 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-25 11:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
A different possible fix is to re-order pattern recog back to before
analyzing data ref accesses.  Vectorization then fails during SLP analysis.

I'm going to test both patches.


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

* [Bug middle-end/61927] [4.9/5 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (6 preceding siblings ...)
  2014-11-25 11:07 ` rguenth at gcc dot gnu.org
@ 2014-11-25 14:56 ` rguenth at gcc dot gnu.org
  2014-11-25 14:56 ` [Bug middle-end/61927] [4.9 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-25 14:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Tue Nov 25 14:55:29 2014
New Revision: 218046

URL: https://gcc.gnu.org/viewcvs?rev=218046&root=gcc&view=rev
Log:
2014-11-25  Richard Biener  <rguenther@suse.de>

    PR tree-optimization/61927
    * tree-vect-loop.c (vect_analyze_loop_2): Revert ordering
    of group and pattern analysis to the one in GCC 4.8.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-vect-loop.c


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

* [Bug middle-end/61927] [4.9 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (7 preceding siblings ...)
  2014-11-25 14:56 ` rguenth at gcc dot gnu.org
@ 2014-11-25 14:56 ` rguenth at gcc dot gnu.org
  2014-11-26 11:43 ` rguenth at gcc dot gnu.org
  2014-11-26 11:45 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-25 14:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |5.0
            Summary|[4.9/5 Regression] Wrong    |[4.9 Regression] Wrong
                   |results with loop           |results with loop
                   |vectorization of: "var[i] = |vectorization of: "var[i] =
                   |ABS_EXPR<var2[i]>  >        |ABS_EXPR<var2[i]>  >
                   |9.9e-7"                     |9.9e-7"

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk sofar.


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

* [Bug middle-end/61927] [4.9 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (8 preceding siblings ...)
  2014-11-25 14:56 ` [Bug middle-end/61927] [4.9 " rguenth at gcc dot gnu.org
@ 2014-11-26 11:43 ` rguenth at gcc dot gnu.org
  2014-11-26 11:45 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-26 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Wed Nov 26 11:42:44 2014
New Revision: 218078

URL: https://gcc.gnu.org/viewcvs?rev=218078&root=gcc&view=rev
Log:
2014-11-26  Richard Biener  <rguenther@suse.de>

    Backport from mainline
    2014-11-26  Richard Biener  <rguenther@suse.de>

    PR tree-optimization/62238
    * tree-predcom.c (ref_at_iteration): Unshare the expression
    before gimplifying it.

    * gcc.dg/torture/pr62238.c: New testcase.

    2014-11-25  Richard Biener  <rguenther@suse.de>

    PR tree-optimization/61927
    * tree-vect-loop.c (vect_analyze_loop_2): Revert ordering
    of group and pattern analysis to the one in GCC 4.8.

    2014-11-07  Richard Biener  <rguenther@suse.de>

    PR tree-optimization/63605
    * fold-const.c (fold_binary_loc): Properly use element_precision
    for types that may not be scalar.

    * gcc.dg/vect/pr63605.c: New testcase.

    2014-10-28  Richard Biener  <rguenther@suse.de>

    PR middle-end/63665
    * fold-const.c (fold_comparison): Properly guard simplifying
    against INT_MAX/INT_MIN with !TYPE_OVERFLOW_WRAPS.

    * gcc.dg/pr63665.c: New testcase.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/pr63665.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/torture/pr62238.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/vect/pr63605.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/fold-const.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_9-branch/gcc/tree-predcom.c
    branches/gcc-4_9-branch/gcc/tree-vect-loop.c


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

* [Bug middle-end/61927] [4.9 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]>  > 9.9e-7"
  2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
                   ` (9 preceding siblings ...)
  2014-11-26 11:43 ` rguenth at gcc dot gnu.org
@ 2014-11-26 11:45 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-26 11:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
      Known to fail|                            |4.9.2

--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.


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

end of thread, other threads:[~2014-11-26 11:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-27 16:55 [Bug fortran/61927] New: Optimization bug (regression): Array comparison yields unassigned result at -O3 krefson at gmail dot com
2014-07-27 16:56 ` [Bug fortran/61927] " krefson at gmail dot com
2014-07-27 21:30 ` [Bug middle-end/61927] [4.9/4.10 Regression] Optimization bug: " burnus at gcc dot gnu.org
2014-08-11 10:01 ` [Bug middle-end/61927] [4.9/4.10 Regression] Wrong results with loop vectorization of: "var[i] = ABS_EXPR<var2[i]> > 9.9e-7" jakub at gcc dot gnu.org
2014-10-30 10:41 ` [Bug middle-end/61927] [4.9/5 " jakub at gcc dot gnu.org
2014-11-24 13:03 ` rguenth at gcc dot gnu.org
2014-11-25 10:53 ` rguenth at gcc dot gnu.org
2014-11-25 11:07 ` rguenth at gcc dot gnu.org
2014-11-25 14:56 ` rguenth at gcc dot gnu.org
2014-11-25 14:56 ` [Bug middle-end/61927] [4.9 " rguenth at gcc dot gnu.org
2014-11-26 11:43 ` rguenth at gcc dot gnu.org
2014-11-26 11:45 ` rguenth 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).