[Bug target/70354] New: [6 Regression] Wrong code with -O3 -march=broadwell and -march=skylake-avx512.

vsevolod.livinskij at frtk dot ru gcc-bugzilla@gcc.gnu.org
Tue Mar 22 11:09:00 GMT 2016


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

            Bug ID: 70354
           Summary: [6 Regression] Wrong code with -O3 -march=broadwell
                    and -march=skylake-avx512.
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

Created attachment 38055
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38055&action=edit
Reproducer.

Test case produces incorrect result with -O3 -march=broadwell. Also it fails
with -march=skylake-avx512, but with different result. Everything works fine
with gcc version 4.9.4 20160318 (prerelease) (Revision=234347) and gcc version
5.3.1 20160318 (Revision=234347).

Output:
> g++ -std=c++11 -O0 -march=broadwell -o out repr.cpp; ./out
6060289626626340782
> g++ -std=c++11 -O3 -march=broadwell -o out repr.cpp; ./out
7868099280905707034
> g++ -std=c++11 -O3 -march=skylake-avx512 -o out repr.cpp; sde -skx -- ./out
2358867323763884526

GCC version:
> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/export/users/vlivinsk/gcc-trunk/bin/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /export/users/vlivinsk/gcc-trunk/gcc/configure
--with-arch=corei7 --with-cpu=corei7 --enable-clocale=gnu --with-system-zlib
--enable-shared --with-demangler-in-ld --enable-cloog-backend=isl
--with-fpmath=sse --enable-checking=release --enable-languages=c,c++,lto
--with-gmp=/export/users/vlivinsk/gcc-trunk/gmp-6.1.0/bin
--with-mpfr=/export/users/vlivinsk/gcc-trunk/mpfr-3.1.3/bin
--with-mpc=/export/users/vlivinsk/gcc-trunk/mpc-1.0.3/bin
--prefix=/export/users/vlivinsk/gcc-trunk/bin
Thread model: posix
gcc version 6.0.0 20160319 (experimental) (Revision=234350)

Test (unfortunately, I failed to reduce it further):
#include <iostream>

void hash(unsigned long long int &seed, unsigned long long int const &v) {
    seed ^= v + 0x9e3779b9 + (seed<<6) + (seed>>2);
}

unsigned long long int a [1000];
long int b [1000];
long int c [1000];
unsigned long int d [1000];
unsigned long int e [1000];
unsigned long long int f [1000];
long int g [1000];
long int h [1000];

void init () {
    for (int i = 0; i < 1000; ++i) {
        a [i] = 14694295297531861425ULL;
        b [i] = -1725558902283030715L;
        c [i] = 4402992416302558097L;
        d [i] = 2890788459207692227UL;
        e [i] = 6297173129107286501UL;
        f [i] = 13865724171235650855ULL;
        g [i] = 982871027473857427L;
        h [i] = 8193845517487445944L;
    }
}

void foo () {
    for (int i = 449; i < 768; i = ((i) + (3))) {
        d [i] = h [i] << (((((unsigned long int)b [i] * e [i]) << (-a [i] -
3752448776177690134ULL)) - 8214565720323784703UL) - 1UL);
        e [i] = (bool)(f [i] + (unsigned long long int)g [i]);
        g [i] = c [i];
    }
}

unsigned long long int checksum () {
    unsigned long long int seed = 0ULL;
    for (int i = 0; i < 1000; ++i) {
        hash(seed, d [i]);
        hash(seed, e [i]);
        hash(seed, f [i]);
        hash(seed, g [i]);
        hash(seed, h [i]);
    }
    return seed;
}
int main () {
    init ();
    foo ();
    std::cout << checksum () << std::endl;
    return 0;
}


More information about the Gcc-bugs mailing list