public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kretz at kde dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/95493] New: [10 Regression] test for vector members apparently reordered with assignment to vector members
Date: Wed, 03 Jun 2020 07:49:08 +0000	[thread overview]
Message-ID: <bug-95493-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 95493
           Summary: [10 Regression] test for vector members apparently
                    reordered with assignment to vector members
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kretz at kde dot org
  Target Milestone: ---

Test case (https://godbolt.org/z/egnkd7), compile with `-O2 -std=c++17`:

#include <cstdio>

struct verify
{
  const bool m_failed = false;

  [[gnu::noinline]] void print_hex(const void* x, int n) const
  {
    const auto* bytes = static_cast<const unsigned char*>(x);
    for (int i = 0; i < n; ++i)
      __builtin_fprintf(stderr, (i && i % 4 == 0) ? "'%02x" : "%02x",
bytes[i]);
    __builtin_fprintf(stderr, "\n");
  }

  template <typename... Ts>
  verify(bool ok, const Ts&... extra_info) : m_failed(!ok)
  {
    if (m_failed)
      (print_hex(&extra_info, sizeof(extra_info)), ...);
  }

  ~verify()
  {
    if (m_failed)
      __builtin_abort();
  }
};

using K [[gnu::vector_size(16)]] = int;

int
main()
{
  int count = 1;
  asm("" : "+m"(count));
  verify(count == 1, 0, "", 0);

  {
    struct SW
    {
      K d;
    };
    struct
    {
      SW d;
    } xx;
    SW& x = xx.d;
    x = SW(); // [0, 0, 0, 0]
    for (int i = 3; i >= 2; --i)
      {
        x.d[i] = -1; // [0, 0, 0, -1] ...
        int a = [](K y) {
          for (int j = 0; j < 4; ++j)
            if (y[j] != 0)
              return j;
          return -1;
        }(x.d);
        verify(a == i, 0, 0, 0, 0, i, x);
      }
  }
}


The relevant code here is:
```
using K [[gnu::vector_size(16)]] = int;
K x = K(); // [0, 0, 0, 0]
int i = 3;
x[i] = -1; // [0, 0, 0, -1]
int j;
for (j = 0; j < 4; ++j)
  if (x[j] != 0)
     break;
if (i != j) abort();
```

In a larger testcase I could see the assignment `x[i] = -1` getting reordered
with the "count zero" function in the disassembled test case.

             reply	other threads:[~2020-06-03  7:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03  7:49 kretz at kde dot org [this message]
2020-06-03  8:15 ` [Bug tree-optimization/95493] [10/11 Regression] test for vector members apparently reordered with assignment to vector members since r10-7523-gb90061c6ec090c6b marxin at gcc dot gnu.org
2020-06-03  8:20 ` [Bug middle-end/95493] " pinskia at gcc dot gnu.org
2020-06-03  9:51 ` [Bug rtl-optimization/95493] " rguenth at gcc dot gnu.org
2020-06-03 10:00 ` rguenth at gcc dot gnu.org
2020-06-03 11:15 ` rguenth at gcc dot gnu.org
2020-06-05  6:35 ` cvs-commit at gcc dot gnu.org
2020-06-05  6:36 ` [Bug rtl-optimization/95493] [10 " rguenth at gcc dot gnu.org
2020-06-16 11:57 ` rguenth at gcc dot gnu.org
2020-06-16 12:58 ` redi at gcc dot gnu.org
2020-06-16 22:15 ` cvs-commit at gcc dot gnu.org
2020-06-19 12:08 ` kretz at kde dot org
2020-06-19 12:29 ` rguenth at gcc dot gnu.org
2020-06-23 13:31 ` cvs-commit at gcc dot gnu.org
2020-06-23 13:31 ` rguenth 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-95493-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).