[Bug tree-optimization/29798] New: -O2 gives wrong results

jpr at csc dot fi gcc-bugzilla@gcc.gnu.org
Fri Nov 10 14:24:00 GMT 2006


Hi,

-O2 gives wrong results. Assingment to a variable (rho) directly affects
value of another (oldrho). Look at the code at the end of the message (it's
modified from the *.102t.final_cleanup of a fortran code, in case you wonder).

gcc-version:

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /home/fxcoudert/gfortran_nightbuild/trunk/configure
--prefix=/home/fxcoudert/gfortran_nightbuild/irun-20061109
--enable-languages=c,fortran
--with-gmp=/home/fxcoudert/gfortran_nightbuild/software
Thread model: posix
gcc version 4.3.0 20061109 (experimental)

Regards, Juha



void main()
{
  double temp167;
  double temp157;
  double rho;
  double D1530;
  double D1537;
  double D1568;
  double D1576;
  double D1578;
  double D1591;
  double alpha;
  double residual;
  int iter_count;
  double beta;
  double oldrho;
  double val19;
  double val24;
  double D1453;
  double xvec[2];
  double rhsvec[2];
  double work[8];

  xvec[0]    = 0.0;
  rhsvec[0]  = 1.0e+0;
  xvec[1]    = 0.0;
  rhsvec[1]  = 2.0e+0;
  work[6]    = xvec[0];
  work[7]    = xvec[1] * 5.0e-1;
  work[6]    = rhsvec[0] - work[6];
  work[7]    = rhsvec[1] - work[7];
  iter_count = 1;

while(1) {
  work[4] = work[6];
  work[5] = work[7];
  work[0] = work[4];
  D1530 = work[5];
  work[1] = D1530;
  D1537 = work[0];

  fprintf( stderr, "1: %d %g\n", iter_count, oldrho );
  rho = work[6] * D1537 + D1530 * work[7];
  fprintf( stderr, "2: %d %g\n\n", iter_count, oldrho );

  if (iter_count == 1) {
    work[2] = D1537;
    work[3] = work[1];
  } else {
    beta = rho / oldrho;
    work[2] = D1537 + beta * work[2];
    work[3] = work[1] + beta * work[3];
  }

  work[4] = work[2];
  D1568 = work[3] * 5.0e-1;
  work[5] = D1568;
  D1576 = work[2];
  D1578 = work[4];
  val19 = D1576 * D1578 + 0.0;
  temp167 = work[3];
  alpha = rho / (val19 + D1568 * temp167);
  xvec[0] = xvec[0] + D1576 * alpha;
  D1591 = xvec[1] + temp167 * alpha;
  xvec[1] = D1591;
  work[6] = work[6] - alpha * D1578;
  work[7] = work[7] - alpha * work[5];
  work[0] = xvec[0];
  work[1] = D1591 * 5.0e-1;
  work[0] = work[0] - rhsvec[0];
  temp157 = work[1] - rhsvec[1];
  work[1] = temp157;
  D1453 = work[0];
  val24 = D1453 * D1453;

  residual = sqrt (val24 + temp157 * temp157);
  if (residual < 1e-12) break;

  iter_count = iter_count + 1;
  if (iter_count == 20) break;

  oldrho = rho;
}

  fprintf( stderr, "%d %g %g\n", iter_count, xvec[0], xvec[1] );
  return;
}


-- 
           Summary: -O2 gives wrong results
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jpr at csc dot fi
  GCC host triplet: x86 linux


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



More information about the Gcc-bugs mailing list