|Non-Confidential||PDF version||ARM 100891_0607_01_en|
|Home > Coding Considerations > Best practices to enable auto-vectorization|
To encourage the SVE Compiler to produce optimal auto-vectorized output, code can be structured and hints provided to inform the compiler of program features that it would otherwise not be able to determine. This allows the compiler to produce optimal auto-vectorized output.
restrict keyword (or the
__restrict__ keyword) indicates
to the compiler that a specified pointer does not alias with any other pointers for
the lifetime of that pointer. This guidance allows the compiler to vectorize loops
more aggressively, since it becomes possible to prove that loop iterations are
independent and can be executed in parallel.
If these keywords are used erroneously (that is, if another pointer is used to access the same memory) then the behavior is undefined. It is possible that the results of optimized code will differ from that of its unoptimized equivalent.
The compiler supports pragmas that you can use to explicitly indicate that loop iterations are completely independent from each other. See Using pragmas to encourage or suppress auto-vectorization for more details and examples.
Where possible, use
!= when constructing loops. This helps the compiler to prove that a
loop terminates before the index variable wraps.
The compiler might also be able to perform more loop optimizations if signed integers are used, because the C standard allows for undefined behavior in the case of signed integer overflow. This is not the case for unsigned integers.
As highlighted in the description of the
this can significantly improve the quality of generated code, but it does so at the
expense of strict compliance with IEEE and ISO standards for mathematical
operations. Ensure that your algorithms are tolerant of potential inaccuracies that
could be introduced by the use of this option.