public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions
@ 2013-05-22 21:42 jewillco at osl dot iu.edu
  2013-05-22 21:47 ` [Bug tree-optimization/57380] " jewillco at osl dot iu.edu
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jewillco at osl dot iu.edu @ 2013-05-22 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57380
           Summary: GCC 4.9.0 will not vectorize std::max and similar
                    functions
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jewillco at osl dot iu.edu

It appears that having a function that returns a const reference to one of its
arguments causes vectorization of calls to that function to fail.  Here is a
simple test program:

struct my_array {
  int data[4] __attribute__((aligned(16)));
};

const int& my_max(const int& a, const int& b) {
  return a < b ? b : a;
}

int f(my_array a, my_array b) {
  int res = 0;
  for (int i = 0; i < 4; ++i) {
    res += my_max(a.data[i], b.data[i]);
  }
  return res;
}

The signature of my_max is a specialization of the one of std::max; std::max
itself has similar problems.  The loop will vectorize without trouble if my_max
returns "int".  The main errors from the vectorization report seem to be:

vec_min_max.cpp:11: note: not vectorized: not suitable for gather load _6 =
*iftmp.0_12;

vec_min_max.cpp:11: note: bad data references.

Other variants of the code get "control flow in loop" instead.  The flags I am
using are:

-ftree-vectorizer-verbose=4 -Ofast -march=nocona

but the code should be able to vectorize under SSE2.  The GCC version I am
using is "g++ (GCC) 4.9.0 20130519 (experimental)" on x86-64.  GCC 4.7.2 has a
similar error, while "4.4.7 20120313 (Red Hat 4.4.7-3)" can vectorize it
without problems.


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

* [Bug tree-optimization/57380] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
@ 2013-05-22 21:47 ` jewillco at osl dot iu.edu
  2013-05-23  8:35 ` [Bug tree-optimization/57380] [4.7/4.8/4.9 Regression] " rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jewillco at osl dot iu.edu @ 2013-05-22 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jeremiah Willcock <jewillco at osl dot iu.edu> ---
I tested version "(Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3" and that fails as well
(with "note: not vectorized: data ref analysis failed D.2097_9 = *D.2115_16;"
in the vectorization report).


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

* [Bug tree-optimization/57380] [4.7/4.8/4.9 Regression] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
  2013-05-22 21:47 ` [Bug tree-optimization/57380] " jewillco at osl dot iu.edu
@ 2013-05-23  8:35 ` rguenth at gcc dot gnu.org
  2013-05-23  9:20 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-23  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2013-05-23
      Known to work|                            |4.5.4
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
   Target Milestone|---                         |4.7.4
            Summary|GCC 4.9.0 will not          |[4.7/4.8/4.9 Regression]
                   |vectorize std::max and      |GCC 4.9.0 will not
                   |similar functions           |vectorize std::max and
                   |                            |similar functions
     Ever confirmed|0                           |1

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
For some reason phiprop doesn't work here.  I'll investigate, but I guess
it is because the addresses are not constant but depend on the loop IV:

  <bb 3>:
  _3 = &b.data[i_2];
  _4 = &a.data[i_2];
  _10 = MEM[(const int &)&a].data[i_2];
  _11 = MEM[(const int &)&b].data[i_2];
  if (_10 < _11)
    goto <bb 5>;
  else
    goto <bb 4>;

  <bb 4>:

  <bb 5>:
  # iftmp.0_12 = PHI <_3(3), _4(4)>

  <bb 6>:
  _6 = *iftmp.0_12;


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

* [Bug tree-optimization/57380] [4.7/4.8/4.9 Regression] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
  2013-05-22 21:47 ` [Bug tree-optimization/57380] " jewillco at osl dot iu.edu
  2013-05-23  8:35 ` [Bug tree-optimization/57380] [4.7/4.8/4.9 Regression] " rguenth at gcc dot gnu.org
@ 2013-05-23  9:20 ` rguenth at gcc dot gnu.org
  2013-05-23 12:24 ` [Bug tree-optimization/57380] [4.7/4.8 " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-23  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
There was a deliberate change to require at least one invariant address or
a re-use of a previous load.

 2010-07-08  Richard Guenther  <rguenther@suse.de>

+       PR tree-optimization/44831
+       * tree-ssa-phiprop.c (phiprop_insert_phi): Properly build
+       a MEM_REF preserving TBAA info of the original dereference.
+       Dereference the original pointer if the address is not
+       invariant.
+       (propagate_with_phi): Fixup type checks wrt MEM_REFs.  Require
+       at least one invariant address that we are going to dereference.

I have a fix.


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

* [Bug tree-optimization/57380] [4.7/4.8 Regression] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
                   ` (2 preceding siblings ...)
  2013-05-23  9:20 ` rguenth at gcc dot gnu.org
@ 2013-05-23 12:24 ` rguenth at gcc dot gnu.org
  2013-10-30 12:23 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-23 12:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.9.0
            Summary|[4.7/4.8/4.9 Regression]    |[4.7/4.8 Regression] GCC
                   |GCC 4.9.0 will not          |4.9.0 will not vectorize
                   |vectorize std::max and      |std::max and similar
                   |similar functions           |functions
      Known to fail|4.9.0                       |4.8.1

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Thu May 23 12:23:59 2013
New Revision: 199246

URL: http://gcc.gnu.org/viewcvs?rev=199246&root=gcc&view=rev
Log:
2013-05-23  Richard Biener  <rguenther@suse.de>

    PR tree-optimization/57380
    * tree-ssa-phiprop.c (propagate_with_phi): Do not require at
    least one invariant or re-used load.
    * passes.c (init_optimization_passes): Move pass_phiprop before
    pass_forwprop.

    * g++.dg/tree-ssa/pr57380.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/tree-ssa/pr57380.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/passes.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-phiprop.c


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

* [Bug tree-optimization/57380] [4.7/4.8 Regression] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
                   ` (3 preceding siblings ...)
  2013-05-23 12:24 ` [Bug tree-optimization/57380] [4.7/4.8 " rguenth at gcc dot gnu.org
@ 2013-10-30 12:23 ` rguenth at gcc dot gnu.org
  2014-01-16 21:04 ` law at redhat dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-30 12:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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

* [Bug tree-optimization/57380] [4.7/4.8 Regression] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
                   ` (4 preceding siblings ...)
  2013-10-30 12:23 ` rguenth at gcc dot gnu.org
@ 2014-01-16 21:04 ` law at redhat dot com
  2014-01-16 21:04 ` law at redhat dot com
  2014-06-30  2:01 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2014-01-16 21:04 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at redhat dot com> changed:

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

--- Comment #6 from Jeffrey A. Law <law at redhat dot com> ---
fixed on trunk


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

* [Bug tree-optimization/57380] [4.7/4.8 Regression] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
                   ` (5 preceding siblings ...)
  2014-01-16 21:04 ` law at redhat dot com
@ 2014-01-16 21:04 ` law at redhat dot com
  2014-06-30  2:01 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2014-01-16 21:04 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at redhat dot com

--- Comment #5 from Jeffrey A. Law <law at redhat dot com> ---
Richi fixed on the trunk many months ago.


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

* [Bug tree-optimization/57380] [4.7/4.8 Regression] GCC 4.9.0 will not vectorize std::max and similar functions
  2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
                   ` (6 preceding siblings ...)
  2014-01-16 21:04 ` law at redhat dot com
@ 2014-06-30  2:01 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-06-30  2:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This testcase fails with -fPIC.


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

end of thread, other threads:[~2014-06-30  2:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-22 21:42 [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions jewillco at osl dot iu.edu
2013-05-22 21:47 ` [Bug tree-optimization/57380] " jewillco at osl dot iu.edu
2013-05-23  8:35 ` [Bug tree-optimization/57380] [4.7/4.8/4.9 Regression] " rguenth at gcc dot gnu.org
2013-05-23  9:20 ` rguenth at gcc dot gnu.org
2013-05-23 12:24 ` [Bug tree-optimization/57380] [4.7/4.8 " rguenth at gcc dot gnu.org
2013-10-30 12:23 ` rguenth at gcc dot gnu.org
2014-01-16 21:04 ` law at redhat dot com
2014-01-16 21:04 ` law at redhat dot com
2014-06-30  2:01 ` pinskia 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).