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

            Bug ID: 78769
           Summary: [7 Regression] Incorrect arithmetic optimization for
                    (a < 0) << 29 >> 1;
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: babokin at gmail dot com
  Target Milestone: ---

> cat bug.cpp
#include <stdio.h>
char a = -110;
unsigned long long int b;

void foo();

int main() {
  foo();
  printf("0x%llx\n", b);
  return 0;
}

> cat bug2.cpp
extern char a;
extern unsigned long long int b;
void foo() {
  b = (a < 0) << 29 >> 1;
}

> g++ -w -O0 -o no_opt bug.cpp bug2.cpp
> ./no_opt
0x10000000

> g++ -w -O1 -o opt bug.cpp bug2.cpp
> ./opt
0x0

> 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_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++,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++,lto
--no-create --no-recursion
Thread model: posix
gcc version 7.0.0 20161209 (experimental) (GCC)

Reply via email to