advice #30008: Consider adding the restrict qualifier to the definition of inp1, inp2 if they don't access the same memory location.
This Advice is issued to alert you to a potential performace improvement in your code. The performance of loop mentioned in the Advice can be improved by adding the "restrict" qualifier.
To help the compiler determine memory dependencies, you can qualify a pointer, reference, or array with the restrict keyword. The restrict keyword is a type qualifier that can be applied to pointers, references, and arrays. Its use represents a guarantee by you, the programmer, that within the scope of the pointer declaration the object pointed to can be accessed only by that pointer. Any violation of this guarantee renders the program undefined. (For more information on the "restrict" qualifier see Restrict Type Qualifier).
This practice helps the compiler optimize certain sections of code because aliasing information can be more easily determined. In the below example, the restrict keyword is used to tell the compiler that the function func1 is never called with the pointers a and b pointing to objects that overlap in memory. You are promising that accesses through a and b will never conflict; therefore, a write through one pointer cannot affect a read from any other pointers. The precise semantics of the restrict keyword are described in the 1999 version of the ANSI/ISO C Standard.
Example 1: Use of the restrict Type Qualifier With Pointers
void func1(int * restrict a, int * restrict b) { /* func1's code here */ }
Example 2: Use of the restrict keyword when passing arrays to a function. Here, the arrays c and d should not overlap, nor should c and d point to the same array.
void func2(int c[restrict], int d[restrict]) { int i; for(i = 0; i < 64; i++) { c[i] += d[i]; d[i] += 1; } }
For further information on conveying information to the compiler to improve performance, see C6000_Compiler: Tuning Software Pipelined Loops and Optimization Lab.
When you use mechanisms such as restrict, MUST_ITERATE, or _nassert, you are conveying extra information to the compiler. Always verify all such information is correct for every call.
Qualify declarations of pointers and arrays used in the loop with "restrict".
Want to squeeze a few more Performance Cycles out of your application? Leverage the e2e (Engineer-to-Engineer) online community to get all of your Advice questions answered! Or, give back to the community with your expertise.