Developer Guide and Reference

Contents

GAP Message (Diagnostic ID 30532)

Message

Store the value of the upper-bound expression (%s) of the loop at line %d into a temporary local variable, and use this variable as the new upper-bound expression of the loop. To do this, insert a statement of the form "temp = %s" right before the loop, where "temp" is the newly created local variable. Choose a variable name that is unique, then replace the loop's original upper-bound expression with "temp".

Advice

Use a local-variable for the loop upper-bound if the upper-bound does not change during the execution of the loop. This enables the compiler to recognize the loop as a proper counted do loop, which in turn enables various loop optimizations including vectorization and parallelization.
This message appears when the compiler can output the exact upper-bound variable to be replaced.
Example
Consider the following:
typedef struct { float* data; } Vector;   typedef struct { int len; } NetEnv;  
// This one does not vectorize void mul( NetEnv* ne, Vector* rslt, Vector* den, Vector* num) { float* r; float* d; float* n; int i;   r = rslt->data; d = den->data; n = num->data;   for (i = 0; i < ne->len; ++i) { r[i] = n[i] * d[i]; } return; }
In this case, the compiler is unable to vectorize the loop at setting
O2
, the default.
If you determine it is safe to do so, you can modify the program code as follows:
typedef struct { float* data; } Vector;   typedef struct { int len; } NetEnv;   // This one vectorizes void mul( NetEnv* ne, Vector* rslt, Vector* den, Vector* num) { float* r; float* d; float* n; int i, local_len;   r = rslt->data; d = den->data; n = num->data;   local_len = ne->len; for (i = 0; i < local_len; ++i) { r[i] = n[i] * d[i]; } return; }

Verify

Confirm that the value of the upper-bound expression does not change throughout the entire execution of the loop.