Andrew T
Andrew T

Reputation: 5745

Does my C++ compiler optimize my code?

While using modern C++ compilers (including MSVC, GCC, ICC), how can I say if it has:

  1. parallelized the code
  2. vectorized the loops (or used other specific processor instructions)
  3. unrolled the loops
  4. detected tail-recursion
  5. performed RVO (return-value optimization)
  6. or optimized in some other way

without diving into the assembler code the compiler produces?

Upvotes: 6

Views: 1234

Answers (4)

Osama Daraghme
Osama Daraghme

Reputation: 69

I'm pretty sure that if you use the most depth optimization in your compiler the code will be parallelized and the loops will be vectorized and many other vectorization techniques will work too.

In order to use that much depth, use -O3 command when you run your code.

Upvotes: 0

Macke
Macke

Reputation: 25680

For RVO or other copy-elision stuff, just put some logging (printf) in copy-ctor and dtor of your class. You should see fewer objects being copied around if optimizations are working.

Upvotes: 0

Anycorn
Anycorn

Reputation: 51465

Intel compiler has decent reporting facility. Look up -vec-report and -par-report in reference documentation or in the man page.

g++also has vector reports, look in the man page for "vector", I'd don't think g++ has parallel automatic code generation.

As far as last three things, I'd don't think compilers report that, so you probably have to go to assembly to get that information

Upvotes: 3

paxdiablo
paxdiablo

Reputation: 881553

The only way you can really tell is if you examine the assembler output (which you appear to have discounted). Other than that, you could read the doco to see what types of optimization each level of your compiler provides.

But, in all honesty, if you don't trust that the optimization levels of your compiler are doing the job, you probably won't trust the doco :-)

I would look at the assembler myself, it's the only way you could be truly certain.

Upvotes: 19

Related Questions