views:

316

answers:

4

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?

+13  A: 

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.

paxdiablo
Strictly speaking, this isn't the only way, but it is probably the easiest or best.You can instruct gcc to make verbose dumps between passes with the -fdump... and -d options (mainly for debugging), and for vectorization the exists verbose optimization messages, which exlain, why and where a loop was vectorized, this is for end users too.
drhirsch
Strictly strictly speaking, those dumps could lie. ;) Only the assembly is guaranteed to be correct. :)
jalf
@jalf: no, there could be a conspiracy between MS and/or GNU, with Intel and/or AMD, which means that the CPU spots identifiers steganographically concealed in code from the compiler, and switches into a special mode such that those apparent vector opcodes are de-vectorised, and don't use the SIMD circuitry at all. *If* you want to be silly ;-)
Steve Jessop
@jalf, Steve: http://cm.bell-labs.com/who/ken/trust.html
int3
And on not trusting the docs: http://stackoverflow.com/questions/1778655/how-to-get-gcc-o1-optimization-without-specifying-o1/1782219#1782219
int3
+2  A: 

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

aaa
GCC has automatic parallisation, using `-ftree-vectorize`. Read more about it here - http://gcc.gnu.org/projects/tree-ssa/vectorization.html
LiraNuna
parallelization usually means openMP in context of compiler, vectorization typically implies SIMD instructions.g++ does not have former.
aaa
@unknown: g++ _has_ OpenMP.
int3
A: 

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.

Marcus Lindblom
A: 

openmp for msvc or gcc

http://openmp.org/wp/

plan9assembler