https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61304
Bug ID: 61304 Summary: Missed vectorization: control flow in loop Product: gcc Version: 4.10.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target: x86_64-linux-gnu (taken from a stackoverflow question about a bug in llvm, replace -1 with -2 if you want to test llvm and avoid the bug) gcc -O3 fails to vectorize the following program because it sees control flow in the loop. If I move i++ before the "if", which becomes i == 0, we still fail to vectorize because we get confused about the number of iterations. Finally, if I stop at i == 2048, we do vectorize, but the generated code could do with some improvements (that would be for a different PR though). #include <stdint.h> #include <string.h> int main() { uint32_t i = 0; uint32_t count = 0; while (1) { float n; memcpy(&n, &i, sizeof(float)); if(n >= 0.0f && n <= 1.0f) count++; if (i == -1) break; i++; } return count; }