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

            Bug ID: 78438
           Summary: incorrect comparison optimization
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: babokin at gmail dot com
  Target Milestone: ---

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

> g++ -O0 main.cpp func.cpp -o no_opt; ./no_opt
0
> g++ -O1 main.cpp func.cpp -o opt; ./opt
2

> cat main.cpp
#include <stdio.h>

char C = 0;
int I = 197412621;

void foo();

int main() {
  foo();
  printf("%d\n", C);
}

> cat func.cpp
extern char C;
extern int I;
void foo() {
  C = 0 > (short) (I >> 11);
}

> g++ -v

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/dybaboki/gcc/bin/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../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 --prefix=/home/dybaboki/gcc/bin
--enable-languages=c,c++,fortran,lto : (reconfigured) ../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 --prefix=/home/dybaboki/gcc/bin
--enable-languages=c,c++,fortran,lto : (reconfigured) ../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 --prefix=/home/dybaboki/gcc/bin
--enable-languages=c,c++,fortran,lto : (reconfigured) ../gcc_github/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 --prefix=/home/dybaboki/gcc/bin
--enable-languages=c,c++,fortran,lto --no-create --no-recursion :
(reconfigured) ../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 --prefix=/home/dybaboki/gcc/bin
--enable-languages=c,c++,fortran,lto --no-create --no-recursion
Thread model: posix
gcc version 7.0.0 20161119 (experimental) (GCC)

Reply via email to