https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115385
Bug ID: 115385 Summary: Peeling for gaps can be optimized more or needs to peel more than one iteration Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- Consider void __attribute__((noipa)) foo(unsigned char * __restrict x, unsigned char *y, int n) { for (int i = 0; i < n; ++i) { x[16*i+0] = y[3*i+0]; x[16*i+1] = y[3*i+1]; x[16*i+2] = y[3*i+2]; x[16*i+3] = y[3*i+0]; x[16*i+4] = y[3*i+1]; x[16*i+5] = y[3*i+2]; x[16*i+6] = y[3*i+0]; x[16*i+7] = y[3*i+1]; x[16*i+8] = y[3*i+2]; x[16*i+9] = y[3*i+0]; x[16*i+10] = y[3*i+1]; x[16*i+11] = y[3*i+2]; x[16*i+12] = y[3*i+0]; x[16*i+13] = y[3*i+1]; x[16*i+14] = y[3*i+2]; x[16*i+15] = y[3*i+0]; } } and void __attribute__((noipa)) bar(unsigned char * __restrict x, unsigned char *y, int n) { for (int i = 0; i < n; ++i) { x[16*i+0] = y[5*i+0]; x[16*i+1] = y[5*i+1]; x[16*i+2] = y[5*i+2]; x[16*i+3] = y[5*i+3]; x[16*i+4] = y[5*i+4]; x[16*i+5] = y[5*i+0]; x[16*i+6] = y[5*i+1]; x[16*i+7] = y[5*i+2]; x[16*i+8] = y[5*i+3]; x[16*i+9] = y[5*i+4]; x[16*i+10] = y[5*i+0]; x[16*i+11] = y[5*i+1]; x[16*i+12] = y[5*i+2]; x[16*i+13] = y[5*i+3]; x[16*i+14] = y[5*i+4]; x[16*i+15] = y[5*i+0]; } } for both loops we currently cannot reduce the access for the load from 'y' to not touch extra elements so we force peeling for gaps. But in both cases peeling a single scalar iteration is not sufficient and we get t.c:5:21: note: ==> examining statement: _3 = y[_1]; t.c:5:21: missed: peeling for gaps insufficient for access t.c:7:20: missed: not vectorized: relevant stmt not supported: _3 = y[_1]; we can avoid this excessive peeling for gaps if we narrow the load from 'y' to the next power-of-two size where then it's always sufficient to just peel a single scalar iteration. When the target cannot construct a vector with those elements we'd have to peel more than one iteration.