[cfe-dev] clang miscompile prevents ATLAS build

Clint Whaley whaley at cs.utsa.edu
Sun Sep 4 09:36:26 PDT 2011


Hi,

I believe I've found a bug in clang/llvm on a sandy bridge CPU.  I am using
the svn version of clang downloaded yesterday:
>sb4>clang -v
>clang version 3.0 (trunk 139049)
>Target: x86_64-unknown-linux-gnu
>Thread model: posix


Take this piece of code:
*******************************************************************************
void ATL_UGEMV(const int M, const int N, const double *A, const int lda,
               const double *X, double *Y)
/*
 *  y = [0,1]*y + A*x, A is MxN, storing the transpose of the matrix
 */
{
   double ry, iy;
   const int lda2 = lda+lda;
   int j;
   void dotu_sub(const int, const double*, const int, const double*,
                 const int, double *);

   for (j=0; j < N; j++, A += lda2, Y += 2)
   {
      ry = *Y; iy = Y[1];
      dotu_sub(M, A, 1, X, 1, Y);
      *Y += ry;
      Y[1] += iy;
   }
}
*******************************************************************************

If you compile with
   clang -fomit-frame-pointer -mavx -O2 -m64 -S
I believe you will find that clang waits until *after* the subroutine call
to load the values, at which point they have been overwritten by the call.

In order to get clang to produce the right answer, you must rewrite
the loop in this way:
   for (j=0; j < N; j++, A += lda2, Y += 2)
   {
      double dot[2]
      dotu_sub(M, A, 1, X, 1, dot);
      *Y += dot[0];
      Y[1] += dot[1];
   }

Thanks,
Clint

**************************************************************************
** R. Clint Whaley, PhD ** Assist Prof, UTSA ** www.cs.utsa.edu/~whaley **
**************************************************************************



More information about the cfe-dev mailing list