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

            Bug ID: 70429
           Summary: Wrong code with -O1.
           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 38111
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38111&action=edit
Reproducer.

Test case produces incorrect result with -O1 and all x86 arch. Everything works
fine with -O0 option.

Output:
> g++ -O0 repr.cpp -mavx2; ./a.out
4119272
> g++ -O1 repr.cpp -mavx2; ./a.out
272554728

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 20160327 (experimental) (Revision=234496)

Test:
#include <iostream>
#include <cstdlib>

bool a = 1;
int b = 612010083;

void foo () {
    b = (int)((~7710322944595239647L + 9223372036854775807L) >> a) >> 4;
}

int main () {
    foo ();
    if (b != 4119272)
        abort();
    return 0;
}

Reply via email to