https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65947
Bug ID: 65947 Summary: Vectorizer misses conditional assignment of constant Product: gcc Version: 5.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: alalaw01 at gcc dot gnu.org Target Milestone: --- This testcase: int a[32]; int main(int argc, char **argv) { int res = 3; for (int i = 0; i < 32; i++) if (a[i]) res = 7; return res; } does not vectorize at -O3 on x86_64 or aarch64. tree-if-conversion succeeds, giving a loop of form: <bb 3>: # res_10 = PHI <res_1(4), 3(2)> # i_11 = PHI <i_6(4), 0(2)> # ivtmp_9 = PHI <ivtmp_2(4), 32(2)> _5 = a[i_11]; res_1 = _5 != 0 ? 7 : res_10; i_6 = i_11 + 1; ivtmp_2 = ivtmp_9 - 1; if (ivtmp_2 != 0) goto <bb 4>; else goto <bb 5>; <bb 4>: goto <bb 3>; but -fdump-tree-vect-details shows: test.c:9:3: note: Analyze phi: res_10 = PHI <res_1(4), 3(2)> test.c:9:3: note: reduction: not commutative/associative: res_1 = _5 != 0 ? 7 : res_10; test.c:9:3: note: Unknown def-use cycle pattern. ... test.c:9:3: note: vect_is_simple_use: operand res_10 test.c:9:3: note: def_stmt: res_10 = PHI <res_1(4), 3(2)> test.c:9:3: note: Unsupported pattern. test.c:9:3: note: not vectorized: unsupported use in stmt. test.c:9:3: note: unexpected pattern.