https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114120
Bug ID: 114120 Summary: add reduction with promotion and then truncation poorly vectorized Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Blocks: 53947 Target Milestone: --- Target: x86_64 Take: ``` unsigned char f(unsigned char *src) { unsigned sum = 0; for(int y = 0; y < 8; y++) { sum += src[y]; } return sum; } ``` On x86_64 we should vectorize to the same as what is done for: ``` unsigned char f0(unsigned char *src) { unsigned char sum = 0; for(int y = 0; y < 8; y++) { sum += src[y]; } return sum; } ``` But GCC does not as GCC keeps sum in unsigned and the reduction is done in `unsigned int`. Note LLVM is able to vectorize this decently. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947 [Bug 53947] [meta-bug] vectorizer missed-optimizations