This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/40927] New: Code fails to vectorize in g++ but does vectorize in gcc.


Fails to vectorize when compiled with g++ -ftree-vectorizer-verbose=7 -S -O3
-march=core2 -msse3 -mfpmath=sse  -Wall -o t test.c

$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch_32=i586
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC)



unsigned char cr[4096] __attribute((aligned(16)));
unsigned char cg[4096] __attribute((aligned(16)));
unsigned char cb[4096] __attribute((aligned(16)));

unsigned char pr[4096] __attribute((aligned(16)));
unsigned char pg[4096] __attribute((aligned(16)));
unsigned char pb[4096] __attribute((aligned(16)));

unsigned short noise[4096] __attribute((aligned(16)));
unsigned char out[4096] __attribute((aligned(16)));

int main(int argc, char * argv[]) {
        int i;

        unsigned char * __restrict pcr = cr;
        unsigned char * __restrict pcg = cg;
        unsigned char * __restrict pcb = cb;

        unsigned char * __restrict ppr = pr;
        unsigned char * __restrict ppg = pg;
        unsigned char * __restrict ppb = pb;

        unsigned short * __restrict n = noise;
        unsigned char * __restrict o = out;

//#define VECTORIZE 1
#define FAILVECTORIZE

        for (i = 1024;i > 0; --i) {
                unsigned short r0, r1, r2;
                r0 = pcr[0] - ppr[0]; r1 = pcg[0] - ppg[0]; r2 = pcb[0] -
ppb[0];
#ifdef VECTORIZE
                // This successfully vectorizes.
                unsigned short a0, a1, a2, b0, b1, b2;

                a0 = (r0 >> 8);
                b0 = a0 | 0xff00;
                r0 &= b0;

                a1 = (r1 >> 8);
                b1 = a1 | 0xff00;
                r1 &= b1;

                a2 = (r2 >> 8);
                b2 = a2 | 0xff00;
                r2 &= a2;
#endif

#ifdef FAILVECTORIZE
                // This fails to vectorize, even though it apparently
                // does exactly the same thing.
                r0 &= (r0>>8) | 0xff00;
                r1 &= (r1>>8) | 0xff00;
                r2 &= (r2>>8) | 0xff00;
#endif
                unsigned short r = r0 + r1 + r2;
                *n = *n + r - (*n>>5);
                *o = r;
                ++n; ++o;
                ++pcr; ++pcg; ++pcb;
                ++ppr; ++ppg; ++ppb;
        }

}


-- 
           Summary: Code fails to vectorize in g++ but does vectorize in
                    gcc.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: public at dgmo dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]