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

            Bug ID: 87074
           Summary: Vectorization bug: O3 result differ from O2
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: konstantin.vladimirov at gmail dot com
  Target Milestone: ---

Reproduction:

long b;
unsigned c[5];
unsigned long long d = 3;
int e, f, g;

void h() {
  for (; f < 11; f++) {
    b = g;
    for (e = 0; e < 5; e++) {
      c[e] = e - b - (c[e] >> 5);
      g = c[e];
    }
  }
  if (c[0])
    d = 0;
}

int main() {
  h();
  return d;
}

Compiler:

> gcc -v

Reading specs from
/apps/gcc/8.1.0/.bin/../lib64/gcc/x86_64-suse-linux/8.1.0/specs
COLLECT_GCC=/apps/gcc/8.1.0/.bin/gcc
COLLECT_LTO_WRAPPER=/apps/gcc/8.1.0/.bin/../libexec/gcc/x86_64-suse-linux/8.1.0/lto-wrapper
Target: x86_64-suse-linux
Configured with: ./configure --prefix=/apps/gcc/8.1.0
--libdir=/apps/gcc/8.1.0/lib64 --libexecdir=/apps/gcc/8.1.0/libexec
--bindir=/apps/gcc/8.1.0/bin --with-isl=/apps/gcc/8.1.0
--with-libelf=/apps/gcc/8.1.0 --with-mpfr=/apps/gcc/8.1.0
--with-gmp=/apps/gcc/8.1.0 --with-mpc=/apps/gcc/8.1.0
--disable-gnu-unique-object --enable-gold=yes --enable-lto
--enable-languages=c,c++,objc,fortran --build=x86_64-suse-linux
--host=x86_64-suse-linux --target=x86_64-suse-linux --enable-libotm
--disable-multilib --disable-bootstrap --disable-libstdcxx-pch
Thread model: posix
gcc version 8.1.0 (GCC)


Compile and run with:

> gcc -O2 minimize.c
> ./a.out
> echo $?
0

> gcc -O3 minimize.c
> ./a.out
> echo $?
3

0 is correct, 3 is incorrect

I also tried with sanitizer, just in case I missed some UB here

> gcc -O2 -fsanitize=undefined minimize.c
> ./a.out

Sanitizer catchs nothing. So if there is really UB (not sure) it is sanitizer
bug.

Clang 6 returns 0 in both cases. GCC 7.3.0 also returns 0 both times.

Reply via email to