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

            Bug ID: 128005
           Summary: wrong code at -O2 and -O3 for a dot-product loop over
                    _BitInt(3) arrays
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

_BitInt(3) a[64], b[64];

__attribute__((noipa)) int f(void) {
  int acc = 0;
  for (int i = 0; i < 64; i++)
    acc += (int)a[i] * (int)b[i];
  return acc;
}

int main(void) {
  for (int i = 0; i < 64; i++) {
    _BitInt(3) x = (i % 7) - 3, y = (i % 5) - 2;
    __builtin_memcpy(&a[i], &x, sizeof x);
    __builtin_memcpy(&b[i], &y, sizeof y);
  }
  if (f() != -6)
    __builtin_abort();
}

godbolt: https://godbolt.org/z/6ehh8doGa

With -O0, -O1 or -O2 -fno-tree-vectorize, f returns -6 and the program exits
normally, but with -O2 or -O3 the loop in f is vectorized and the program
aborts.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.
  • [Bug tree-optimization/128005] N... kyuwoncho18 at gmail dot com via Gcc-bugs

Reply via email to