Answered by:
C++ Compiler Optimization Broken in VS2013 and VS2015

Question
-
I've noticed today that many of my compiled projects are now much larger than previously.
After investigating it looks like the compiler is no longer optimizing code during compilation.
I have tested with a simple Win32 Console App, with the code below, however the test string is showing in the compiled code!
I would be grateful, if others on the forum can confirm this as an issue (and perhaps any kind of solution?)
#include "stdafx.h" #define debug 0 int main() { if (debug > 0) { fprintf(stderr, "This should not appear in the compiled code!!!!!\n"); } return 0; }
Wednesday, February 17, 2016 12:51 PM
Answers
-
Yes I believe it is definitely a repro case, although I'm at a loss as to explain what the cause is.
All I know for sure at the moment is:
I have one machine that has only ever had VS2013 installed, and that machine still builds projects correctly, so building with "Full Optimization" the compiled code is optimized as expected.
I have three other machines, that have VS2013 installed, but they also have VS2015 installed, and on those machines if I build the same project either using VS2015 or VS2013 using "Full Optimization", the compiled code exhibits the issue and does not appear to be optimized in any way.
I'll get an issue raised on connect, and let you know here once done.
Wednesday, February 17, 2016 11:25 PM
All replies
-
In debug configuration, optimization is disabled so this is normal. Do you see this in release config?
Wednesday, February 17, 2016 2:07 PM -
No this is occurring in release config.
I have tested with VS2013 Update 3, and VS3013 Update 4, and with both the optimization works as expected.
I am seeing this issue on both VS2013 Update 5 and VS2015 Update 1. (Tested on 3 different machines, with the same results, where in release config the optimization does not work)
I'm currently installing VS2013 Update 5 to try to work out if the problem was introduced in Update 5.
- Edited by JonesJ76 Wednesday, February 17, 2016 3:02 PM
Wednesday, February 17, 2016 2:15 PM -
I have now tested on a standalone development machine that ONLY has VS2013 Update 5, installed and the compilation works as expected.
However, on 3 other machines that have BOTH VS2013 Update 5 and VS2015 Update 1 installed, the VS2013 build fails to optimize the compilation correctly.
Is it possible that VS2015 is causing this issue?
Wednesday, February 17, 2016 4:34 PM -
I have now tested on a standalone development machine that ONLY has VS2013 Update 5, installed and the compilation works as expected.
However, on 3 other machines that have BOTH VS2013 Update 5 and VS2015 Update 1 installed, the VS2013 build fails to optimize the compilation correctly.Which toolset do you have set for the project?
Dave
Wednesday, February 17, 2016 4:49 PM -
When building from VS2013 I'm using the "Visual Studio 2013 (v120)" toolset
Wednesday, February 17, 2016 4:56 PM -
-
From VS2015, I've tried both "Visual Studio 2013 (v120)" and "Visual Studio 2015 (v140)" and even the xp variants of both, all four toolsets exhibit the same issue.
Wednesday, February 17, 2016 5:47 PM -
>From VS2015, I've tried both "Visual Studio 2013 (v120)" and "Visual Studio 2015 (v140)" and even the xp variants of both, all four toolsets exhibit the same issue.
Odd!
I've just tried pasting your code into a default Win32 console project
and I'm building with VS2015 with the CTP update 2 - I can find no
sign of that string in the EXE if I open the built EXE in VS's binary
editor.I don't have VS2013 installed though, only 2015 & 2010.
Dave
Wednesday, February 17, 2016 6:32 PM -
Thanks for testing on your kit, did you try with the Optimization flag set to: "Full Optimization /Ox" or "Maximize Speed (/O2)" ?
The issue I'm seeing seems only to manifest when using Full Optimization, if I use Maximize Speed, then the string does not appear in the exe, but if I use "Full Optimization" then the string does appear.
Wednesday, February 17, 2016 6:55 PM -
Thanks for testing on your kit, did you try with the Optimization flag set to: "Full Optimization /Ox" or "Maximize Speed (/O2)" ?
The default release build /O2
The issue I'm seeing seems only to manifest when using Full Optimization, if I use Maximize Speed, then the string does not appear in the exe, but if I use "Full Optimization" then the string does appear.
OK, I can confirm the same then, a build with /Ox does have the string
in the EXE.Dave
Wednesday, February 17, 2016 7:54 PM -
I can repro this too with /Ox but not with /O2, on VS2015 Express Upd 1. Have also VS 2013 Community Upd 5. on the machine.
-- pa
Wednesday, February 17, 2016 8:07 PM -
So, do you now think the differences you were seeing with different
versions were red herrings, and the real difference is due to the
optimization option?If you've got a solid repro case (it seemed that way to me), I suggest
that you report it to MS on the connect site
(https://connect.microsoft.com/visualStudio/) and post a link to your
report back here so that we can validate it.Dave
Wednesday, February 17, 2016 10:40 PM -
Yes I believe it is definitely a repro case, although I'm at a loss as to explain what the cause is.
All I know for sure at the moment is:
I have one machine that has only ever had VS2013 installed, and that machine still builds projects correctly, so building with "Full Optimization" the compiled code is optimized as expected.
I have three other machines, that have VS2013 installed, but they also have VS2015 installed, and on those machines if I build the same project either using VS2015 or VS2013 using "Full Optimization", the compiled code exhibits the issue and does not appear to be optimized in any way.
I'll get an issue raised on connect, and let you know here once done.
Wednesday, February 17, 2016 11:25 PM -
Thursday, February 18, 2016 3:01 AM