http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50599
Bug #: 50599 Summary: -ftree-vectorize generating incorrect code Classification: Unclassified Product: gcc Version: 4.5.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: a5970...@nepwk.com MinGW x86 4.5.2 A loop: while(total_out < decompressed_size) { printf("%X\n",p); int chunk_size = *(int*)p; if(chunk_size > 0) { int ret = params->decompressor(p+sizeof(int), chunk_size, params->out+total_out, std::min(params->osize-total_out,params->bsize), params->other); int real_out = (ret / params->ssize) * params->ssize; if(real_out != ret) real_out += params->ssize; if(total_out + real_out >= params->isize) total_out += ret; else total_out += real_out; p += chunk_size+sizeof(int); } else { if(params->verify) { memcpy(params->out+total_out, p+sizeof(int), -chunk_size); p += -chunk_size; } total_out += -chunk_size; p += sizeof(int); } } Compiled with -O3 -fno-strict-aliasing works funny - the printf is called twice with the same address. And on some data I'm getting crashes in params->decompressor, which is a 3rd party code. I added other printfs and I see that when running the loop for the 1st time, the code enters the 1st branch, goes to p += chunk_size+sizeof(int), increases, goes out of the if and iterates the loop again with unchanged p. Adding -fno-tree-vectorize solves the problem.