https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126079
Bug ID: 126079
Summary: BB vectorization of loads with gaps is not handled
well
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
Split out from PR126053 where we have roughly
double x[4];
void foo (double *p)
{
int tem0 = x[0];
int tem1 = x[1];
int tem2 = x[2];
int tem3 = x[3];
tem0 = tem0 + p[0];
tem1 = tem1 + p[1];
tem2 = tem2 + p[2];
tem3 = tem3 + p[2];
x[0] = tem0;
x[1] = tem1;
x[2] = tem2;
x[3] = tem3;
}
and
t2.c:13:8: note: ==> examining statement: _6 = *p_25(D);
t2.c:13:8: missed: BB vectorization with gaps at the end of a load is not
supported
t2.c:9:18: missed: not vectorized: relevant stmt not supported: _6 =
*p_25(D);
t2.c:13:8: note: Building vector operands of 0x9d6be10 from scalars instead
while we vectorize the above testcase because it's still profitable, we
miss out doing a SSE vector load {p[0], p[1]} plus a splat {p[2], p[2]}
which would be cheaper than three scalar loads(?).
We expand from
_6 = *p_25(D);
_9 = MEM[(double *)p_25(D) + 8B];
_40 = {_6, _9};
_12 = MEM[(double *)p_25(D) + 16B];
_39 = {_12, _12};
but in the end manage
movupd (%rdi), %xmm0
movsd 16(%rdi), %xmm2
unpcklpd %xmm2, %xmm2
so recover code-gen wise on the RTL side.
Adding
p = __builtin_assume_aligned (p, 32);
also shows we are not exploiting alignment guarantees.
We have some related bugs (one with gap in the middle), but none exact
duplicate I think.