https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120972
Bug ID: 120972
Summary: restrict does not work for not-parameter pointer
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: fxue at os dot amperecomputing.com
Target Milestone: ---
We could get the below loop vectorized with options "-Ofast -S -mavx512f
--param vect-max-version-for-alias-checks=0", since __restrict__ on parameters
could ensure no alias among memory accesses.
void add(char* __restrict__ a0, char * __restrict__ b0, char * __restrict__ c0,
int n, int m)
{
double *__restrict__ a = (double *) &a0[m];
double *__restrict__ b = (double *) &b0[m];
double *__restrict__ c = (double *) &c0[m];
for(int i = 0; i < n; i++)
c[i] = a[i] + b[i];
}
But alias-analysis does not follow the same assumption for __restrict__
non-parameter pointers, as the result, a modified case below could not be
vectorized with the same options, since runtime alias checks are disabled.
char *ga();
char *gb();
char *gc();
void add(int n)
{
double *__restrict__ a = (double *) ga();
double *__restrict__ b = (double *) gb();
double *__restrict__ c = (double *) gc();
for(int i = 0; i < n; i++)
c[i] = a[i] + b[i];
}