public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jewillco at osl dot iu.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/57380] New: GCC 4.9.0 will not vectorize std::max and similar functions
Date: Wed, 22 May 2013 21:42:00 -0000	[thread overview]
Message-ID: <bug-57380-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2013-05-22 21:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-22 21:42 jewillco at osl dot iu.edu [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-57380-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).