Home Dashboard Directory Help
Search

Bug in x64 C++ compiler (optimizer) by Bert Rodiers


Status: 

Active


5
0
Sign in
to vote
Type: Bug
ID: 525943
Opened: 1/20/2010 1:54:07 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

We are having crashes in LAPACK and BLAS code (Fortran code automatically converted to C++) when we compile for 64 bit in release mode. When using 64-bit Debug mode, 32-bit release mode or 32-bit debug mode there isn't any problem.

We have downsized the problem to the minimal code that still crashed. The code below allows to reproduce the problem

// VSTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <ctype.h>
#include <math.h>
#include <string.h>

//#define NO_OPTIMIZATIONS 1

#ifdef NO_OPTIMIZATIONS
#if defined (_M_X64)
#pragma optimize( "", off )
#endif
#endif

void dtrmv(const long &n, double *a, const long &lda, double x[])
{
#define A(I_,J_) (*(a+(I_)*(lda)+(J_)))
    double temp;

    //        Form x := A'*x.

    for( int j = n, j_ = j - 1; j >= 1; j--, j_-- ) {
        temp = x[j_];
        temp = temp*A(j_,j_);
        for( int i = j - 1, i_ = i - 1; i >= 1; i--, i_-- ) {
            temp = temp + A(j_,i_)*x[i_];
        }
        x[j_] = temp;
    }

#undef A
}

#ifdef NO_OPTIMIZATIONS
#if defined (_M_X64)
#pragma optimize( "", on )
#endif
#endif


int _tmain(int argc, _TCHAR* argv[])
{

    double* t = new double[64*65];
    memset(t,0,64*65*sizeof(double));

#define T(I_,J_) (*(t+(I_)*(65)+(J_)))

    dtrmv( 5, t, 65, &T(31, 0));

    delete t;
    return 0;
}


The crash is at this line of code while executing the code:
temp = temp + A(j_,i_)*x[i_];
and on this instruction:000000014000112A mulsd xmm0,mmword ptr [rcx+8]

[rcx+8] should be the memory address of A(_j,_i), but the memory that is being accessed is quite before the start of the "matrix" A.

When you step through the disassembly, systematically the wrong address in the memory space is being accessed, both for A(j_,i_) and for x[i_].

When creating this example we didn't change the default settings in the Visual Studio project, except changing the platform (to X64) and the configuration (to Release).
We have inspected the C++ code and believe it is correct.

When the following line is uncommented:
//#define NO_OPTIMIZATIONS 1
the code works. Hence if we disable the optimizations we have no problem.
However it is rather painful having to disable optimizations for the most performance critical code.
Details
Sign in to post a comment.
Posted by Microsoft on 2/1/2010 at 2:02 PM
Thank you for the request. I apologize for the inconvenience.

Do you have any previous case number (via Clarify or MS Solve)? We can open a new support case using the same entitlements as the previous case.

If not, you can contact Scot directly and he will assist you in getting a new support case created. His contact is:

Scot Brennecke
EE for VC++/MFC/ATL, C#, VB.NET, CLR, Visual Studio
ScotBren@Microsoft.com
(469) 775-6164, 09:30 to 18:30 CT
Posted by Microsoft on 2/1/2010 at 2:02 PM
Thank you for the request. I apologize for the inconvenience.

Do you have any previous case number (via Clarify or MS Solve)? We can open a new support case using the same entitlements as the previous case.

If not, you can contact Scot directly and he will assist you in getting a new support case created. His contact is:

Scot Brennecke
EE for VC++/MFC/ATL, C#, VB.NET, CLR, Visual Studio
ScotBren@Microsoft.com
(469) 775-6164, 09:30 to 18:30 CT
Posted by Bert Rodiers on 1/29/2010 at 2:32 AM
Thank you for the reply.
We are currently using Visual Studio 2005 and are planning to move to Visual Studio 2010 this year. We would like to have this problem fixed in the short time for Visual Studio 2005 because some of our customers need to have this working. We could use the workaround mentioned in this forum, however the code pattern comes back in a lot of source files and we hence we might have to fix a lot of code (and potentially introducing new problems).
To obtain a hotfix we also submitted this problem on the partner development forums (we are a Gold partner), and there they advised us to phone to the support center. When we did this they referred us to the website https://members.microsoft.com/omc/welcome.aspx to submit the bug, but we believe this is not the website where we can submit bugs or request hot fixes.
We tried submitting at https://support.microsoft.com/oas/ however we get the error message that our Product Identificatie nummer (PID) is not valid (we copied the one that is shown in the About Microsoft Visual Studio window).
I also tried submitting a bug report for VS 2005 on the connect site, but I'm only able to do this for VS 2008 and VS 2010, not for VS 2005.

To make a long story short, is it possible to also create a hotfix for VS 2005? And if this is not the right place to request this, what is the best way to request a hotfix (in a way that doesn't lead me to another dead-end).
Posted by Microsoft on 1/28/2010 at 12:28 PM
Thanks for the feedback. To keep performance, you might try the following workaround: replace the inner loop with code below

int i = j - 1, i_ = i - 1;
while (i>=4) {
    double temp1 = A(j_,i_)*x[i_];
    double temp2 = A(j_,i_ - 1)*x[i_ - 1];
    double temp3 = A(j_,i_ - 2)*x[i_ - 2];
    double temp4 = A(j_,i_ - 3)*x[i_ - 3];
    temp = temp + temp1 + temp2 + temp3 + temp4;
    i -= 4;
    i_-= 4;
}

while (i >= 1) {
    temp = temp + A(j_,i_)*x[i_];
    i--;
        i_--;
}
Posted by Microsoft on 1/26/2010 at 2:25 PM
Thanks for the feedback. We are investigating the issue, and will be fixing it for a future release.
Posted by Microsoft on 1/21/2010 at 7:52 PM
Thanks for your feedback.

We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.
These specialized experts will follow-up with your issue.
Sign in to post a workaround.