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.