[Bug c/86947] New: Erroneous code generated with O2 and O3 for PPC

vinay.kumar at blackfigtech dot com gcc-bugzilla@gcc.gnu.org
Tue Aug 14 08:27:00 GMT 2018


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

            Bug ID: 86947
           Summary: Erroneous code generated with O2 and O3 for PPC
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vinay.kumar at blackfigtech dot com
  Target Milestone: ---

Created attachment 44534
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44534&action=edit
Testcase to reproduce the bug.

$powerpc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/data/home/toolchain/ppc/prefix/bin/powerpc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/data/home/toolchain/ppc/prefix/bin/../libexec/gcc/powerpc-linux-gnu/8.1.0/lto-wrapper
Target: powerpc-linux-gnu
Configured with: /data/home/toolchain/ppc/build/../src/gcc-8.1.0/configure
--target=powerpc-linux-gnu --prefix=/data/home/toolchain/ppc/build/../prefix
--disable-nls --enable-languages=c,c++ --enable-targets=all --disable-multilib
--disable-libsanitizer --enable-threads --enable-tls --enable-__cxa_atexit
--enable-secureplt --with-gmp=/data/home/toolchain/gmp-mpfr-mpc/prefix
--with-mpfr=/data/home/toolchain/gmp-mpfr-mpc/prefix
--with-mpc=/data/home/toolchain/gmp-mpfr-mpc/prefix
--prefix=/data/home/toolchain/ppc/build/../prefix
Thread model: posix
gcc version 8.1.0 (GCC)

The testcase was compiled using following command and options:-
$powerpc-linux-gnu-gcc -m64 -O2 test.c -S

Please note the following chunk of code in the assembly file:-
There is a comparison of the registers R7 and R31.
However, the register R31 is not being initialized and optimized away 
and generating wrong code.
========================================================
.L4:
        addis 9,2,.LC2@toc@ha
        ld 9,.LC2@toc@l(9)
        lfd 12,0(9)nd 
        fcmpu 7,12,31
        bng 7,.L20
        stfd 31,112(1)
========================================================

We have investigated this issue and observed that its not observed with
O1 and Os optimization levels. Its only been the issue with O2 & O3.
The generated code was correct on disabling the optimization flags
"fno-tree-pre" and "fno-gcse" for O2 flags. It was also investigated on 
the earlier GCC source code and observed that issue is present atleast
until gcc-4.3.3 sources.

Thanks,
Vinay Kumar


More information about the Gcc-bugs mailing list