Compilation of the attached code (adapted from
http://gcc.gnu.org/projects/tree-ssa/vectorization.html
example3) 

* works and vectorizes with gcc-4.0.1
  g++ -O -msse -ftree-vectorizer -c vect.cpp
* works with gcc-4.1.0 and 4.2.0-20060311 if one of the above options is
omitted
  (but does not or not fully vectorize...)
* fails with gcc-4.1.0 and 4.2.0-20060311
  g++ -O -msse -ftree-vectorizer -c vect.cpp
  [...] "alignment of array elements is greater than element size"

I have more examples. I tried on PentiumIV and AMD64. The error is triggered
when a pointer to a 16-byte aligned int (or double, or float) is used as class
member or as a local variable or argument in a member function. It seems that
pointers in member functions are treated as arrays. 

I think this is a bug, since the same code in a C-style function does not
trigger the error. It essentially prevents the use of SSE alignment with C++
and severely limits opportunities for auto-vectorization.

/* begin vect.cpp */
typedef int aint __attribute__ ((__aligned__(16)));

void foo (int n, aint * __restrict__ p, aint * __restrict q) 
{   while (n--) *p++ = *q++;   }

struct toto {
  static void foo (int n, aint * __restrict__ p, aint * __restrict q) 
  {   while (n--)  *p++ = *q++;  }
};

void tata(int n, aint * __restrict__ p, aint * __restrict q)
{
  toto x;
  x.foo(n,p,q);
}
/* end vect.cpp */


-- 
           Summary: pointers to 16-byte aligned ints are rejected in member
                    functions
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dubos at lmd dot polytechnique dot fr
  GCC host triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26654

Reply via email to