Home Dashboard Directory Help
Search

Problem with compiler optimization by paulus wahl


Status: 

Closed
 as Deferred Help for as Deferred


2
0
Sign in
to vote
Type: Bug
ID: 774941
Opened: 12/21/2012 4:42:05 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

Hi,
Today i was figthing with wrong calculation results.
After debugging a while, it seems that the compiler generates wrong machine code.
This error occurs only when the optimization is switched on (Maximize Speed).

In order to investigate this problem in more detail, i copied some lines of code into a standard WinMain function.
There i got the same result.

I am using Visual Studio Express 2012 for Windows Desktop Version 11.0.51106.01 Update 1

kind regards,
Pauli
Details
Sign in to post a comment.
Posted by Microsoft on 2/1/2013 at 3:42 PM
Hi, thanks for the great bug report. This is a bug in the compiler optimizer. You can work around this in the source code by disabling vectorization for this loop, using #pragma loop(no_vector) immediately above the 'while' loop.

If you feel you would like a hotfix for VS 2012, please visit the support site:

http://support.microsoft.com/common/international.aspx?RDPATH=dm;en-us;selectassist&target=assistance

I am closing this MSConnect item. Feel free to re-activate it if you need anything else.

Thanks,
Eric Brumer - Microsoft Visual C++
Posted by Microsoft on 12/23/2012 at 11:18 PM
Thanks for your feedback.

We are rerouting 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.
Posted by UnitUniverse on 12/22/2012 at 5:31 AM
The v110, v110_xp and v120_CTP_Nov2012 all hit this bug...
Posted by paulus wahl on 12/21/2012 at 10:26 AM
Hi, in the mean time i found the exact reason.
Here is some output of the disassembly window, along with some comments:

    int idx=0;
    while(idx<ptCnt)
    {
        pPolyIn[idx].X-=shiftToCenterX;
00C01080 movsd     xmm0,mmword ptr [eax+18h]
00C01085 movsd     xmm1,mmword ptr [eax]
        pPolyIn[idx].X*=-1;
        idx++;
00C01089 add         eax,30h
00C0108C unpcklpd    xmm1,xmm0
00C01090 subpd     xmm1,xmm3
00C01094 movlpd     qword ptr [eax-30h],xmm1
00C01099 movhpd     qword ptr [eax-18h],xmm1
***********
Here is one line missing, XMM0 is not initialized with 'movsd     xmm1,mmword ptr [eax-18h] '
and therefore XMM0 contains it's original value of 12.
three lines later xmm1 is multiplied with -1 (xmm4),
and this is the reason for having '-11, -12' in the array (instead of '-11, -11')
***********
00C0109E movsd     xmm1,mmword ptr [eax-30h]
00C010A3 unpcklpd    xmm1,xmm0
00C010A7 mulpd     xmm1,xmm4
00C010AB movlpd     qword ptr [eax-30h],xmm1
00C010B0 movhpd     qword ptr [eax-18h],xmm1
00C010B5 dec         ecx
00C010B6 jne         wWinMain+80h (0C01080h)
    }

So for me it seems that the compiler 'forgets' about one line of code.
Hope that helps.

cu Pauli
Posted by Microsoft on 12/21/2012 at 4:55 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
ConsoleApplication1.zip 12/22/2012 8 KB
ConsoleApplication1.zip 12/22/2012 8 KB