Search

Incorrect code generation when optimizing and using SSE2 by yuriks

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 647064
Opened: 2/24/2011 6:07:23 PM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
When compiling the attached program with /O1 (or, by uncommenting the marked line in the source, with /O2.) and /arch:SSE2 the compiler generates incorrect code which causes wrong results to be calculated.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Reliability

Steps to reproduce

1. Use version 16.00.30319.01 for 80x86 of the C++ Microsoft compiler;
2. Either:
a) Use commandline "cl.exe main.cpp /O1 /arch:SSE2";
b1) Uncomment line 17 on the source, and
b2) Use command line: "cl.exe main.cpp /O2 /arch:SSE2";

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

C:\Users\yuriks\projetos\vcbug>make_release.bat

C:\Users\yuriks\projetos\vcbug>cl main.cpp /EHsc /O1 /arch:SSE2
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

main.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.

/out:main.exe
main.obj

C:\Users\yuriks\projetos\vcbug>main.exe
0
1
2
3
4
5
6
7
8

C:\Users\yuriks\projetos\vcbug>

Expected results

C:\Users\yuriks\projetos\vcbug>make_debug.bat

C:\Users\yuriks\projetos\vcbug>cl main.cpp /EHsc /arch:SSE2
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

main.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.

/out:main.exe
main.obj

C:\Users\yuriks\projetos\vcbug>main.exe
8

C:\Users\yuriks\projetos\vcbug>
File Attachments
File Name Submitted By Submitted On File Size  
main.cpp 2/24/2011 434 bytes
Sign in to post a comment.
Posted by Microsoft on 3/1/2011 at 12:28 PM
Thank you for the bug report. We are aware of this issue and will fix this in the next major product release.
In the meantime, you may need to workaround the problem by disabling optimization for the affected function.

Mark Levine
Visual C++
Posted by Microsoft on 2/25/2011 at 1:49 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 2/24/2011 at 6:14 PM
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)
Posted by yuriks on 2/24/2011 at 6:12 PM
Thought I may as well post the source of the test case here:

/////////////////////////////////////
#include <iostream>
#include <cmath>

struct data
{
    float val;
};

void func(const data& origin)
{
    data tmp = origin;
    tmp.val += 1.f;
    int upz = int(tmp.val);
    int z = int(origin.val);
    for (; z < upz; ++z) {
        float value1 = std::sin(z * 2.f);
        // This needs to be added on /O2: std::cout << value << '\n';
        std::cout << z << '\n';
    }
}

int main()
{
    data origin = {8.f};
    func(origin);
    return 0;
}
/////////////////////////////////////
Sign in to post a workaround.