[EMAIL PROTECTED] wrote on 07/10/2008 10:48:29:
> Dear gcc developers, > > I am new to this list. > I tried to use the auto-vectorization (4.2.1 (SUSE Linux)) but unfortunately > with limited success. > My code is bassically a matrix library in C++. The vectorizer does not like > the member variables. Consider this code compiled with > gcc -ftree-vectorize -msse2 -ftree-vectorizer-verbose=5 -funsafe- > math-optimizations.... > that gives basically "not vectorized: unhandled data-ref" The unhandled data-ref here is sum. It is invariant in the loop, and invariant data-refs are currently unsupported by the data dependence analysis. If you can change your code to pass sum by value, it will get vectorized (at least with gcc 4.3). This is not C++ specific problem (for me your C version does not get vectorized either because of the same reason). HTH, Ira, > <C++ code snippet> > class P{ > public: > P() : m(5),n(3) { > double *d = data; > for (int i=0; i<m*n; i++) > d[i] = i/10.2; > } > void test(const double& sum); > private: > int m; > int n; > double data[15]; > }; > > void P::test(const double& sum) { > double *d = this->data; > for(int i=0; i<m*n; i++){ > d[i]+=sum; > } > } > </C++ code snippet> > whereas the more or less equivalent C version works just fine: > <C code snippet> > int m=5; > int n=3; > double data[15]; > > void test(const double& sum) { > int mn = m*n; > for(int i=0; i<mn; i++){ > data[i]+=sum; > } > } > </C code snippet> > > Is there a fundamental problem in using the vectorizer in C++? > > Regards! > Georg > [attachment "signature.asc" deleted by Ira Rosen/Haifa/IBM]