[Bug tree-optimization/88732] New: different results on -O0 and -O1, -O2, -O3, -Os

2019-01-06 Thread amocywang at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88732

Bug ID: 88732
   Summary: different results on -O0 and -O1, -O2, -O3, -Os
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: amocywang at gmail dot com
  Target Milestone: ---

> $ gcc -v  
>   
>
Using built-in specs.
COLLECT_GCC=/home/wgc/installs/gcc_trunks/trunk_r267598/bin/gcc
COLLECT_LTO_WRAPPER=/home/wgc/installs/gcc_trunks/trunk_r267598/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure LDFLAGS=-Wl,--no-as-needed
--prefix=/home/wgc/installs/gcc_trunks/trunk_r267598
--with-gmp=/home/wgc/installs/gmp-6.1.2
--with-mpfr=/home/wgc/installs/mpfr-4.0.1
--with-mpc=/home/wgc/installs/mpc-1.1.0 --with-isl= --with-cloog=
--enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
gcc version 9.0.0 20190105 (experimental) (GCC)

$ gcc -O0 program.c
$ ./a.out
63
$ gcc -O1 program.c
$ ./a.out
64 
$ gcc -O2 program.c
$ ./a.out
64
$ gcc -O3 program.c
$ ./a.out
64
$ gcc -Os program.c
$ ./a.out
64

$ cat program.c
static int a, b;
unsigned short int c() {
  b = __builtin_clzl(a);
  return a;
}
int main() {
  c();
  printf("%d\n", b);
  return 0;
}

I have validated this difference with the command line option
"-fno-strict-aliasing -fwrapv" and the results are different on different
optimizing options, same with the results above. It seems the test program is
correct.

[Bug tree-optimization/88732] different results on -O0 and -O1, -O2, -O3, -Os

2019-01-06 Thread amocywang at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88732

--- Comment #2 from Amos Wang  ---
(In reply to Marc Glisse from comment #1)
> Why not read the documentation for that function?
> "If x is 0, the result is undefined."

Why the results are different at different optimizing optionss? If it's an
undefined behaviour, I think all results should be the same.