gcc-help-owner@xxxxxxxxxxx wrote on 24/08/2009 23:31:45: > My loop doesn't vectorize. The message says: > > ./TestAutoVect.cpp:31: note: not vectorized: unhandled data-ref > > 22 > //----------------------------------------------------------------------------- > 23 void MaskRGBA( > 24 const int *in, > 25 const int * const inEnd, > 26 int *out, > 27 const int * const m) > 28 { > 29 for (;in<inEnd; ++in, ++out) > 30 { > 31 *out=*in&*m; > 32 } > 33 } The problem is that '*m' cannot be taken out of the loop because the alias analysis cannot prove that it doesn't alias other memory accesses in the loop. This causes data references analysis to fail since the above access is loop invariant. Therefore, this loop is not vectorized. > > I found that when I change it to this > > 23 > //----------------------------------------------------------------------------- > 24 void MaskRGBA( > 25 const int *in, > 26 const int * const inEnd, > 27 int *out, > 28 const int * const mask) > 29 { > 30 const int m=*mask; > 31 for (;in<inEnd; ++in, ++out) > 32 { > 33 *out=*in&m; > 34 } > 35 } Here there is no such problem. > > It gets vectorized. What is the reason behind that? > You can also use __restrict__ to help vectorization: void MaskRGBA( const int *__restrict__ in, const int * const __restrict__ inEnd, int *__restrict__ out, const int * const __restrict__ m) { for (;in<inEnd; ++in, ++out) { *out=*in&*m; } } Ira