GAP Message -remark #30537: (LOOP) Add the "restrict" keyword to each pointer-typed formal parameter of the routine "foo" ...

Message 30537

Add the "restrict" keyword to each pointer-typed formal parameter of the routine "foo". This allows optimizations such as parallelization and vectorization to be applied to the loop at line 9. [VERIFY] Make sure that semantics of the "restrict" pointer qualifier is satisfied: in the routine, all data accessed through the pointer must not be accessed through any other pointer.

Description

Rather than using option -fnoargument-alias (Linux* OS and Mac OS* X) or /Qno-alias-args (Windows* OS), which affects the entire file, you can add the restrict qualifier to the pointer arguments to this routine. This change is more localized since it affects only the routines where the keyword is applied.
The restrict qualifier is part of C standard C99. This qualifier can be applied to a data pointer to indicate that during the scope of that pointer declaration, all data accessed through it will be accessed only through that pointer but not through any other pointer. So, the restrict keyword enables the compiler to perform certain optimizations based on the premise that a given object cannot be changed through another pointer. You must ensure that restrict-qualified pointers are used as they are intended to be used. Otherwise, undefined behavior may result.
The Intel compiler requires that you also specify option -restrict (Linux* OS and Mac OS* X) or /Qrestrict (Windows* OS) when compiling non-C99 programs.

Example

void matrix_mul_matrix(int  N, float * C,  float  *A,  float  *B) {
  int  i,j,k;
 
  for (i=0; i<N; i++) {
    for (j=0; j<N; j++) {
      C[i*N+j]=0;
      for(k=0;k<N;k++)
      {
        C[i*N+j]+=A[i*N+k] * B[k*N+j];
      }
    }
  }
}

In this case, the compiler is unable to apply loop optimizations such as loop-interchange and vectorization at setting O2, the default. If you determine it is safe to do so, you can modify the program code as follows:

void matrix_mul_matrix(int  N, float * restrict C,  float  * restrict A,  float
 * restrict B) {
  int  i,j,k;
 
  for (i=0; i<N; i++) {
    for (j=0; j<N; j++) {
      C[i*N+j]=0;
      for(k=0;k<N;k++)
      {
        C[i*N+j]+=A[i*N+k] * B[k*N+j];
      }
    }
  }
}

Note that instead of using the restrict qualifier, you could have specified -fnoargument-alias or /Qno-alias-args before compiling the code.

 

Make sure that semantics of the "restrict" pointer qualifier is satisfied: in the routine, all data accessed through the pointer must not be accessed through any other pointer.

 

Optimization Notice in English

Tags:
For more complete information about compiler optimizations, see our Optimization Notice.