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

            Bug ID: 85989
           Summary: Incorrect result for example involving unary minus in
                    a loop
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ketan.surender at gmail dot com
  Target Milestone: ---

Created attachment 44208
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44208&action=edit
Preprocessed reproduction file

Please see the attached file 'standalone.i'. When I run this in -O0 I see the
result

gcc -Wall -Wstrict-aliasing=0 -O0 standalone.i -o standalone
./standalone

--> 0
--> 0

This is what I expect. If I compile with '-O1' I see

gcc -Wall -Wstrict-aliasing=0 -O1 standalone.i -o standalone
./standalone

--> 8
--> 8

Which is unexpected. I poked around in gdb and stared at the asm in godbolt and
it seems like the negation is being omitted in the following loop:

  for (b_P5 = 0; b_P5 < 8; b_P5++) {
    P26 = P29;
    P29 = -(int)*P5;
  }

Here is my gcc info

Using built-in specs.
COLLECT_GCC=[SNIP]/glnxa64/gcc-6.3.0/bin/gcc
COLLECT_LTO_WRAPPER=[SNIP]/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: [SNIP]/sources/gcc-6.3/configure
--with-gmp=[SNIP]/glnxa64/gcc-6.3/gmp-4.3 --with-mpfr=[SNIP]/gcc-6.3/mpfr
--with-mpc=[SNIP]/gcc-6.3/mpc --enable-languages=c,c++,fortran
--with-bugurl=[SNIP],_Debugging --enable-shared --enable-linker-build-id
--enable-plugin --enable-checking=release --enable-multiarch --enable-gold
--enable-ld=default --enable-libstdcxx-time=no
--prefix=[SNIP]/glnxa64/gcc-6.3.0 --with-pkgversion='MW GCC 6.3.0-GLIBC2.12'
--with-tune=generic --with-system-zlib --enable-multilib
--with-multilib-list=m32,m64 --with-arch-directory=amd64 --with-arch-32=i586
--with-abi=m64
Thread model: posix
gcc version 6.3.0 (MW GCC 6.3.0-GLIBC2.12)

Reply via email to