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

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).