https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103144
Bug ID: 103144 Summary: vectorizer failed to recognize shift>>=1 in loop as shift>>i Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: crazylht at gmail dot com Target Milestone: --- Host: x86_64-pc-linux-gnu #include<stdint.h> void foo1 (uint64_t* __restrict pdst, uint64_t* psrc, uint64_t shift) { for (int64_t i = 0; i != 64; i++) { uint64_t shift_i = shift >> i; pdst[i] = psrc[i] + shift_i; } } void foo (uint64_t* __restrict pdst, uint64_t* psrc, uint64_t shift) { for (int64_t i = 0; i != 64; i++) { pdst[i] = psrc[i] + shift; shift >>= 1; } } gcc can vectorize foo1 but not foo since there's cross-iteration dep for shift >>= 1, but shift >>= 1 is just shift >> i in loop. Where should it be handled, can vect_recog_pattern handle this?