Does VS2008 C ++ optimizer sometimes produce slower code?

Following the previous question, I played with the optimizer settings in my release build to find out what benefits should be gained from using compiler optimization. So far I have used / Ob 1 (only built-in, where inline is explicitly specified) and / Oi (Enable internal functions). I tried to change this to turn on / off (use fast code), / Oy (omit pointers to frames) and / Ob 2 (any suitable built-in), and, to my surprise, the regression set, which took 2 hours 58 minutes, took 3h16m. My first assumption was that my own inlining was more aggressive than the compiler, but switching from / Ob 2 to / Ob1 only improved things to 3h12m. I am still doing more tests, but it seems that in some cases / Ot (the preferred fast code) actually slows down. The software is multi-threaded and intensively calculated (surface modeling, manipulation and visualization) and is already highly manually optimized based on profiling results. The program also deals with large amounts of data and quite often uses #pragma pack (4).

So the questions are these. For a manually optimized program, can compiler optimization in VS2008 do more damage than good? In other words, are there well-known documented scenarios in which compiler optimization reduces performance? (nb profiling optimized compiler code is painful, so profiling today is done using non-optimized code).

Change Following Cody Gray's suggestions and other suggestions, I added / O 2 to the optimization settings and re-executed my test suite. This led to a 3x01 launch time, which was comparable to a minimally optimized run. Given the (slightly outdated) MSDN optimization guide lines and the message from GOZ, I'm going to check / O 1 to see if the actual one is actually less faster in my case. Please note that the current exe file is about ~ 11 MB. I will also try to bring VS2010 together and see how it fares.

Edit2 C / O 1 runtime was 3 hours, and 11 MB exe was 62k less. Note that the reason for this post and the previous related one is to verify that the benefits of enabling compiler optimizers outweigh the disadvantages in terms of profiling and debugging. In this particular case, they do not seem like that, although I admit that I am surprised that none of the combinations tried to add any benefit and some obviously reduced performance. FWIW, in accordance with this previous thread , I try to carry out most of my optimization during development and use the profiler primarily to check design assumptions, I believe that I will stick with this approach. I will have one last transition to VS2010 with the optimization of the whole program turned on and leave it on that.

Thanks for all the reviews!

+3
source share
3 answers

The documentation for /Ot states:

If you use /Os or /Ot , you must also specify /Og to optimize the code.

That way you can always go through /Og with /Ot in your tests.

However, /Ot supports fast code due to the size of the program and can create very large binaries, especially with a strong paste. Large binary files have a hard time using the processor cache.

+4
source

It is possible that he is trying to embed large functions, or at least a large number of functions in a loop. At this point, you risk causing a reload of the command cache. This can slow down a lot. Inline is not always the best thing (although most often it is useful). If you have large loops with many function calls, then it is better to split the loop into several loops. This way, the loop can remain inside the command cache, and you get significantly better performance.

+2
source

It is well known that favour fast code not always faster than favour small code . The compiler heuristic is not omniscient, and it may be wrong. In some cases, smaller code is faster than faster code.

Use /O2 for quick code โ€” the compiler knows better how various settings can interact.

Wait. Have you profiled unoptimized code? This is madness. Compiler optimization is not like manual optimization - they are always performed, and there is no reason to profile them - you can identify bottlenecks that do not exist, etc. If you need accurate profiling data, you get a compiler to make it absolute best, and then a profile.

You can also familiarize yourself with the help of profiled optimization, which will help optimize the compiler in some impressive models.

+2
source

Source: https://habr.com/ru/post/897136/


All Articles