gcc: Loop-Specific Pragmas

1 
1 6.61.16 Loop-Specific Pragmas
1 -----------------------------
1 
1 '#pragma GCC ivdep'
1 
1      With this pragma, the programmer asserts that there are no
1      loop-carried dependencies which would prevent consecutive
1      iterations of the following loop from executing concurrently with
1      SIMD (single instruction multiple data) instructions.
1 
1      For example, the compiler can only unconditionally vectorize the
1      following loop with the pragma:
1 
1           void foo (int n, int *a, int *b, int *c)
1           {
1             int i, j;
1           #pragma GCC ivdep
1             for (i = 0; i < n; ++i)
1               a[i] = b[i] + c[i];
1           }
1 
1      In this example, using the 'restrict' qualifier had the same
1      effect.  In the following example, that would not be possible.
1      Assume k < -m or k >= m.  Only with the pragma, the compiler knows
1      that it can unconditionally vectorize the following loop:
1 
1           void ignore_vec_dep (int *a, int k, int c, int m)
1           {
1           #pragma GCC ivdep
1             for (int i = 0; i < m; i++)
1               a[i] = a[i + k] * c;
1           }
1 
1 '#pragma GCC unroll N'
1 
1      You can use this pragma to control how many times a loop should be
1      unrolled.  It must be placed immediately before a 'for', 'while' or
1      'do' loop or a '#pragma GCC ivdep', and applies only to the loop
1      that follows.  N is an integer constant expression specifying the
1      unrolling factor.  The values of 0 and 1 block any unrolling of the
1      loop.
1