Home Dashboard Directory Help
Search

C++ VS2010: bug in generating optimized code with a loop by varaev


Status: 

Closed
 as Fixed Help for as Fixed


3
0
Sign in
to vote
Type: Bug
ID: 740985
Opened: 5/7/2012 12:44:34 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
2
User(s) can reproduce this bug

Description

I originally assumed this is the same bug mentioned here
https://connect.microsoft.com/VisualStudio/feedback/details/737176/msvc10-optimization-bug-loop-optimization-produces-incorrect-code#details

however after some regression testing it turned out that this issue is new to 2010 and cannot be reproduced in 2005 or 2008, while 737176 problem can be traced back at least to 2005, so this seems to be a different, even though possible related issue.

We've recently transitioned to 2010 from 2005 and this problem quickly became a blocker for us: with over 1M codeline base we cannot practically go through all our loop code and disable optimization there with #pragma optimize(). On the other hand, disabling optimization across the product has quite severe performance repercussions, with up to 100% performance hit, since many operations in our product are highly computational intensive. Would you have any other suggestions as to how to deal with this problem?

Thanks in advance!

Ilya Varaev & Michael Yakubovsky
Details
Sign in to post a comment.
Posted by Yang Xiaohui on 5/20/2012 at 7:28 AM
Is "will be fixed in the VS11 release" a satisfied ansower?
What if I won't upgrade?
No service pack planned?
Posted by Yang Xiaohui on 5/16/2012 at 9:11 PM
Your workaround is not acceptible, vs11 does not support Windows XP.
Posted by Microsoft on 5/16/2012 at 8:39 AM
Hi, thanks for the bug report. This is a bug in the compiler optimizer, and will be fixed in the VS11 release. If you need a workaround, your best bet is to turn off optimizations around the affected functions using:

#pragma optimize("", off)
... your funciton ...
#pragma optimize("", on)

The bug only manifests when two specific optimizations kick in. One optimization turns this code:

int x;
...
if (x < 0 || x > 300)

into:

int x;
unsigned int tmp = (unsigned int) x;
if (x > 300)

The second optimization that is required for this bug to manifest changes the induction variable of loops to have fewer operations in the loop body. It turns this code:

for (int i=L; i<U; i++)
if (i*3 > 300)
     func(i*3);

into this:

for (int i=L; i<U; i+=3)
if (i > 100)
     func(i);

The second optimization is buggy (when it rewrites the "i*3 > 100" it loses the fact that i*3 may have been made unsigned by the first optimization). I have fixed this in the VS11 release.

Both of these optimizations are required for the bug to manifest. This is more information than you probably want to know, but it can guide you to where your existing code might be susceptible. For what it's worth, having these two optimizations kick is in extremely rare.

Thanks,
Eric Brumer
Microsoft Visual C++
Posted by MS-Moderator08 [Feedback Moderator] on 5/8/2012 at 12:54 AM
Thank you for submitting feedback on Visual Studio 11 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 MS-Moderator01 on 5/7/2012 at 1:43 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)
Sign in to post a workaround.