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

            Bug ID: 88156
           Summary: ftree-vrp elides sign condition on mingw
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xantares09 at hotmail dot com
  Target Milestone: ---

Using mingw/gcc 8.2.0, at O2 level, ftree-vrp seems to elide the if(h<0)
condition in the following example:

#include <iostream>

int string_hash(const wchar_t* data) {
  int h = 0;

  if (!data){
    return 0;
  }

  while (*data != 0) {
    h = (h * 7) ^ *data;
    ++data;
  }

  if (h < 0) {
    h = -h;
  }

  return h;
}

int main(int argc, char *argv[])
{
  int hash = string_hash(L"PROBABILIT");
  std::cout << "hash= "<<hash<<std::endl;
  return 0;
}

$ x86_64-w64-mingw32-g++ -O2 main.cxx
$ x86_64-w64-mingw32-wine ./a.exe 
hash= -730059684

If I disable ftree-vrp it goes fine:

$ x86_64-w64-mingw32-g++ -O2 -fno-tree-vrp main.cxx 
$ x86_64-w64-mingw32-wine ./a.exe 
hash= 730059684

It's correct too on native gcc:
$ g++ -O2 main.cxx
$ ./a.out 
hash= 730059684


$ x86_64-w64-mingw32-g++ -v
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/8.2.0/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: /home/xantares/.cache/aurman/mingw-w64-gcc/src/gcc/configure
--prefix=/usr --libexecdir=/usr/lib --target=x86_64-w64-mingw32
--enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared
--enable-static --enable-threads=posix --enable-fully-dynamic-string
--enable-libstdcxx-time=yes --with-system-zlib --enable-cloog-backend=isl
--enable-lto --disable-dw2-exceptions --enable-libgomp --disable-multilib
--enable-checking=release
Thread model: posix
gcc version 8.2.0 (GCC)

Reply via email to