7

I want to know compiler optimization strategies for generating optimized object code for my c++ app in Visual studio. Currently i am using default settings.

bjskishore123
  • 6,144
  • 9
  • 44
  • 66
  • What problems are you experiencing that you think will be solved by changing the compiler settings? – ChrisF Aug 21 '10 at 16:25
  • 2
    Project + Properties, C/C++, Optimization. Press F1 to find out what it means. – Hans Passant Aug 21 '10 at 16:32
  • 1
    And don't forget to ship the Release, not the Debug build. –  Aug 21 '10 at 17:28
  • 2
    @jdv: Why. If the debug builds are good enough (you need to define good enough) why not ship the debug build. That why if things go wrong you can debug on site in the environment where they went wrong. – Martin York Aug 21 '10 at 17:41
  • Your question is a bit broad to be answered in a SO answer. It takes an essay to answer it, because the compiler employs __many__ strategies for optimizing the code it generates. Those compiler writing folks have been hammering at the optimizing C++ code for more than three decades, after all, and they did come up with quite a few ideas. – sbi Aug 21 '10 at 18:55
  • Do not forget the Visual C++ floating point model switch: `/fp:fast`. The speedups can be drastic if you are doing a lot of math with `float` or `double`. Read more here: http://blogs.msdn.com/b/vcblog/archive/2015/10/19/do-you-prefer-fast-or-precise.aspx – Special Sauce Dec 30 '15 at 06:20

3 Answers3

3

In short: the main things you would want to play around with are the /O1 and /O2 flags. They set the optimization to either minimize size or maximize speed.

There are a bunch of other settings but you don't really want to be playing around with these unless you really know what you are done and have already measured, profiled and figured out that changing compiler settings is the best way to get better perf or smaller size.

Full link at: http://social.msdn.microsoft.com/forums/en-us/vcgeneral/thread/8931B453-6B0D-46C6-B2C6-EE2BEA2FFB76

obelix
  • 986
  • 8
  • 14
  • 2
    Quoting the salient points of the page linked to saves people *having* to click the link and guards against link rot. – ChrisF Aug 21 '10 at 16:29
  • 1
    +1 - I like your suggestion about profiling before using the other optimization levels. – James Black Aug 21 '10 at 17:49
0

a whole lot of them:
http://en.wikipedia.org/wiki/Optimizing_compiler
http://llvm.org/docs/Passes.html
those are academical techniques so they are transverse to any compiler. You can excpect most to be in visual studio.

v.oddou
  • 6,476
  • 3
  • 32
  • 63