[cfe-dev] clang miscompile prevents ATLAS build

Eli Friedman eli.friedman at gmail.com
Sun Sep 4 12:33:15 PDT 2011


On Sun, Sep 4, 2011 at 9:36 AM, Clint Whaley <whaley at cs.utsa.edu> wrote:
> 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

Don't use -mavx with clang... the support is incomplete at best.  (I'm
actually not entirely sure why exactly the option exists.)

-Eli

> 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 **
> **************************************************************************
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>




More information about the cfe-dev mailing list