restrict on casted pointers
Wed Aug 28 12:19:00 GMT 2013
I have the feeling this is a problem with my understand of restrict so bear with me.
Consider the following:
typedef short int16_t;
typedef int16_t c16mat4by4[10/*rows*/][10/*columns*/];
void nofmat4x4mul_v6(c16mat4by4 C_out, c16mat4by4 D_out, c16mat4by4 A, c16mat4by4 B)
c16mat4by4 * restrict arow_p = (c16mat4by4 *)&(A);
c16mat4by4 * restrict brow_p = (c16mat4by4 *)&(B);
c16mat4by4 * restrict crow_p = (c16mat4by4 *)&(C_out);
c16mat4by4 * restrict drow_p = (c16mat4by4 *)&(D_out);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 5; j++)
for (int z = 0; z < 5; z++)
crow_p[i][j][z] = brow_p[i][j][z] + arow_p[i][j][z];
drow_p[i][j][z] = brow_p[i][j][z];
I would assume that at each cycle brow_p[i][j][z] would only be loaded once due to brow_p and crow_p being marked as restrict. However, this doesn't happen under my port on 4.8.1. I confirmed it doesn't happen either on v850 (compiled with `gcc-v850/gcc/cc1 -O2 -std=c99 -o- restrict.c -fpreprocessed'):
I would have thought the second lh would have been unnecessary.
This means either alias analysis is wrong or my understanding of restrict in this case is wrong. I bet on the latter and that's why this is in gcc-help.
More information about the Gcc-help