http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57512
Bug ID: 57512 Summary: Vectorizer: cannot handle accumulation loop of signed char type Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: bmei at broadcom dot com Created attachment 30249 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30249&action=edit Unvectorized with signed char type. GCC (I used 4.7.2 x86-64 target) cannot vectorize this accumulation loop. gcc tst.c -O2 -S -ftree-vectorize -fdump-tree-vect-details signed short mac_char (signed char * __restrict__ in1, signed char * __restrict__ in2) { unsigned i; signed short sum = 0; for (i = 0; i < 256; i++) { signed char d1 = in1[i]; signed char d2 = in2[i]; sum += ((signed short)d1 * (signed short)d2); } return sum; } If I change signed char to unsigned char, vectorization does work. unsigned short mac_uchar (unsigned char * __restrict__ in1, unsigned char * __restrict__ in2) { unsigned i; unsigned short sum = 0; for (i = 0; i < 256; i++) { unsigned char d1 = in1[i]; unsigned char d2 = in2[i]; sum += ((unsigned short)d1 * d2); } return sum; } Looking into .vect file, I think the problem is with handling following gimple stmts. GCC converts short additions to unsigned short additions and then converts result back to short because of integer promotion. This confuses vectorizer so it cannot find correct vector reduction patterns. D.3015_14 = (short unsigned int) D.3014_13; sum.0_15 = (short unsigned int) sum_25; D.3017_16 = D.3015_14 + sum.0_15; sum_17 = (short int) D.3017_16;