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

            Bug ID: 98949
           Summary: gcc-9.3 aarch64 -ftree-vectorize generates wrong code
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cyb70289 at gmail dot com
  Target Milestone: ---

Assertion fired in below test code when compiled with g++-9.3 aarch64 -O3.
Disable tree-vectorize fixes the issue.
g++-7, g++-10 don't have this problem.

$ uname -m
aarch64

$ g++-9 --version
g++-9 (Ubuntu 9.3.0-11ubuntu0~18.04.1) 9.3.0

$ g++-9 -O3 -march=armv8-a test.cc && ./a.out
a.out: test.cc:27: int main(): Assertion `bitmap[7] != 0' failed.
Aborted (core dumped)

$ g++-9 -O3 -fno-tree-vectorize -march=armv8-a test.cc && ./a.out
[assertion not fired]


test.cc
=======

#include <cassert>
#include <cstdint>

int main(void) {
  uint64_t a[64], b[64];
  for (int i = 0; i < 64; ++i) {
    a[i] = 1;
    b[i] = 2;
  }
  a[63] = b[63];  // only last element is the same

  uint8_t bitmap[8];  // holds 64 bits, bit_i = 1 if (a[i] == b[i]) else 0, i =
0 ~ 63
  int index = 0;  // index to a[], b[]
  for (int byte = 0; byte < 8; ++byte) {
    uint8_t out_results[8]; // holds 8 comparison results temporarily
    for (int bit = 0; bit < 8; ++bit) {
      out_results[bit] = a[index] == b[index];
      ++index;
    }
    bitmap[byte] = (out_results[0] | out_results[1] << 1 | out_results[2] << 2
|
                    out_results[3] << 3 | out_results[4] << 4 | out_results[5]
<< 5 |
                    out_results[6] << 6 | out_results[7] << 7);
  }

  // last bitmap should be non-zero, fired on gcc-9.3 aarch64 -O3
  assert(bitmap[7] != 0);
  return 0;
}

Reply via email to