High-level optimizations (HLO) exploit the properties of source code constructs (for example, loops and arrays) in the applications developed in high-level programming languages, such as C++. The high-level optimizations include loop interchange, loop fusion, loop unrolling, loop distribution, unroll-and-jam, blocking, data prefetch, scalar replacement, data layout optimizations and loop unrolling techniques.
The option required to turn on the high-level optimizations is -O3 (Linux*) or /O3 (Windows*); the scope of optimizations turned on by the option is different for IA-32 and ItaniumŪ-based applications. See Setting Optimization Levels.
The -O3 (Linux) or /O3 (Windows) option enables the -O2 (Linux) or /O2 (Windows) option and adds more aggressive optimizations; for example, loop transformation and prefetching. -O3 (Linux) or /O3 (Windows) optimizes for maximum speed, but may not improve performance for some programs.
In conjunction with the vectorization options, -ax and -x (Linux) or /Qax and /Qx (Windows), the -O3 (Linux) or /O3 (Windows) option causes the compiler to perform more aggressive data dependency analysis than the default -O2 (Linux) or /O2 (Windows). This may result in longer compilation times.
The -ivdep-parallel (Linux) or /Qivdep-parallel (Windows) option asserts there is no loop-carried dependency in the loop where an IVDEP directive is specified. This is useful for sparse matrix applications.
Follow these steps to tune applications on ItaniumŪ-based systems:
Compile your program with -O3 (Linux) or /O3 (Windows) and -ipo (Linux) or /Qipo (Windows). Use profile guided optimization whenever possible.
Identify hot spots in your code.
Turn on Optimization reporting.
Check why loops are not software pipelined:
Use #pragma ivdep to indicate there is no dependence. You might need to compile with the -ivdep-parallel (Linux) or /Qivdep-parallel (Windows) option to absolutely specify no loop carried dependence.
Use #pragma swp to enable software pipelining (useful for lop-sided controls and unknown loop count).
Use #pragma loop count(n) when needed.
Use of -ansi-alias (Linux) or /Qansi-alias (Windows) is helpful. For example, for **p = *q, the ANSI rule indicates the pointer and float data do not overlap.
Add the restrict keyword to insure there is no aliasing.
Use -alias-args (Linux) or /Qalias-args- (Windows) to indicate arguments are not aliased.
Use #pragma distribute point to split large loops (normally this is done automatically).
For C code, do not use unsigned int for loop indexes. HLO may skip optimization due to possible subscripts overflow. If upper bounds are pointer references, assign it to a local variable whenever possible.
Check that the prefetch distance is correct. Use #pragma prefetch to override the distance when it is needed.