Why would std::copy not vectorize?
c++, vectorization
Solution
It seems that your code is fine and it is just an "information" message: See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57579. There, similar code will be vectorized by another method, and therefore the second vectorizing code spits out the informational message that it cannot vectorize (again).
Problem
Consider this general code: ``` #include <cstdlib> #include <ctime> #include <algorithm> // std::copy int main() { const int n=1024; float a1[n],a2[n]; std::srand(std::time(0)); for(int i=0;i<n;i++) a2[i]=std::rand()/(float)RAND_MAX; std::copy(a2,a2+n,a1); } ``` when I compile this with `g++/gcc 4.8.1` and the `-O3 -march=native -mtune=native` flag on Ubuntu, I get that the line corresponding to the copy can't be vectored because: ``` note: not vectorized: not enough data-refs in basic block. ``` If I use ``` for(int i=0;i<n;i++) a1[i]=a2[i]; ``` I also get the same compiler message. I'm a bit puzzled. Intuitively I would think a copy between two non-overlapping array must be eminently vector-able. Can anyone explain why this is not the case (and eventually provide a fix, though admittedly this is not a bottleneck in my code, I'm mostly asking for the sake of understanding what that error message mean).