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

            Bug ID: 117194
           Summary: [15 Regression] Wrong code on highway-1.2.0
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

Noticed on current gcc-master from r15-4419-g6604a05fa27bc2 (did not bisect to
precise commit) `highway-1.2.0` testsuite fails as:

       > The following tests FAILED:
       >        740 - HwyIfTestGroup/HwyIfTest.TestAllIfNegative/EMU128  #
GetParam() = 2305843009213693952 (Subprocess aborted)

Extracted the self-contained example as:

// $ cat /tmp/a.cc
#include <cstdint>
#include <cstddef>

namespace {

struct v8 {
  v8() = default;
  v8(const v8&) = default;
  v8& operator=(const v8&) = default;

  int8_t raw[16] = {};
};

v8 Zero_() { v8 v; return v; }

v8 Iota_(int8_t first) {
  v8 v;
  for (int8_t i = 0; i < 16; ++i) {
    v.raw[i] = first + i;
  }
  return v;
}

v8 Set_(const int8_t t) {
  v8 v;
  for (size_t i = 0; i < 8; ++i) {
    v.raw[i] = t;
  }
  return v;
}

v8 SignBit_() { return Set_(int8_t{-128}); }

v8 Or_(v8 a, v8 b) {
  v8 r;
  for (size_t i = 0; i < 16; ++i) {
    r.raw[i] = a.raw[i] | b.raw[i];
  }
  return r;
}

v8 IfNegativeThenElse(v8 v, v8 yes, v8 no) {
  v8 r;

  for (size_t i = 0; i < 8; ++i) {
    r.raw[i] = v.raw[i] < 0 ? yes.raw[i] : no.raw[i];
  }
  return r;
}

void TestAllIfNegative() {
    const v8 v0 = Zero_();
    const auto vp = Iota_(1);
    const auto vsignbit = SignBit_();
    const auto vn = Or_(vp, vsignbit);
    const auto r = IfNegativeThenElse(vn, v0, vp);

    if (__builtin_memcmp(v0.raw, r.raw, 8) != 0)
        __builtin_trap();
}

} // namespace

int main() {
    TestAllIfNegative();
}

Crashing:

# ok
$ g++ a.cc -O1 -o bug && ./bug
# bad
$ g++ a.cc -O2 -o bug && ./bug
Illegal instruction (core dumped)

$ g++ -v
Reading specs from gcc/specs
COLLECT_GCC=gcc/xg++
COLLECT_LTO_WRAPPER=gcc/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib
--disable-bootstrap --disable-lto --disable-libsanitizer
--disable-libstdcxx-pch --enable-languages=c,c++ --disable-libgomp
--disable-libquadmath --disable-libvtv CFLAGS='-O1 -g0' CXXFLAGS='-O1 -g0'
LDFLAGS='-O1 -g0'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241016 (experimental) (GCC)

Reply via email to