C++ eigen library does vectorization for different architecture, like SSE, NEON etc. In their documentation they mentioned that, Eigen vectorization is not compiler dependent. But most modern compilers like gcc does the vectorization automatically if the vectorization flag is enabled using -O3 flag.

So my question is, why Eigen or any other libraries does this hard coded vectorization when compilers does this automatically for us?

  • 1
    $\begingroup$ You should ask the Eigen developers. Also, the compiler is almost never perfect when it vectorizes, maybe the Eigen developers have done a better job for each architecture. $\endgroup$
    – Bill Barth
    Jul 6, 2016 at 22:54
  • 1
    $\begingroup$ Vectorization in clang appears to be only 4 years old (?): blog.llvm.org/2012/12/new-loop-vectorizer.html $\endgroup$
    – Kirill
    Jul 7, 2016 at 1:00
  • 2
    $\begingroup$ I think that there is a reasonable question at the core that is definitely not off-topic (namely, why do libraries need hand-vectorized code for different architectures if there are -- or claim to be -- auto-vectorizing compilers?) I therefore vote to leave open, hoping that someone more knowledgeable will edit and answer the (general) question. $\endgroup$ Jul 7, 2016 at 15:17

1 Answer 1


It is true that compilers are getting better and better at auto-vectorization, and for basic coefficient-wise operations like 2*A-4*B a library like Eigen cannot do much better than recent compilers. However, for slightly more complicated expressions like matrix products, reductions, transposition, powers, etc. the compiler cannot do much. On the other hand, Eigen can take advantage of the higher level knowledge of the expression semantic to explicitly vectorize them. Moreover, complex scalar types are not vectorized by compilers. You can check by yourself by disabling Eigen's explicit vectorization (-DEIGEN_DONT_VECTORIZE).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.