http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51041

             Bug #: 51041
           Summary: g++ strange optimisation behaviour
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: fb.programm...@gmail.com


The attached code repeatedly executes a vector * vector product to test the
performance of the system. Compiled with

 g++ -Wall -O2 file.cpp

it results in a performance of about 1.7 Gflops on an Intel i5-750, ie
the output is

 adding:          0.059 s, 1.695 GFlops, sum=0.000000

However, when adding another printf (remove the comment in front of the
last printf) the performance deteriorates strongly (same compiler
options):

 adding:          0.195 s, 0.512 GFlops, sum=0.000000
 sum=0.000000

It seems the last printf confuses the compiler optimisation completely,
although it shouldn't make a difference at all, as the same variable
is already printed a few lines above.

This is worrying as it seems the compiler fails to fully optimise the
code under odd circumstances. I've used compiler version 4.6.2 as well as
4.4.1 which is the default compiler on the system.


$ gcc-4.6.2 --version
gcc-4.6.2 (GCC) 4.6.2

$ gcc --version
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]

$ uname -a
Linux localhost 2.6.31.14-0.8-desktop #1 SMP PREEMPT 2011-04-06 18:09:24 +0200
x86_64 x86_64 x86_64 GNU/Linux

Reply via email to