It is not necessary to compile everything with
-qipa,
but try to apply it to as much of your program as possible. Here are
some suggestions:
- Specify the -qipa option on both the
compile and link steps of the entire application. Although you can
also use -qipa with libraries, shared objects,
and executable files, be sure to use -qipa to
compile the main and exported functions.
- When compiling and linking separately, use -qipa=noobject on
the compile step for faster compilation.
- When specifying optimization options in a makefile, remember to
use the compiler driver (xlc) to link,
and to include all compiler options on the link step.
- As IPA can generate significantly larger object files than traditional
compilations, ensure that there is enough space in the /tmp directory
(at least 200 MB). You can use the TMPDIR environment variable to
specify a directory with sufficient free space.
- Try varying the level suboption if link
time is too long. Compiling with -qipa=level=0 can
still be very beneficial for little additional link time.
- Use -qipa=list=long to generate a report
of functions that were previously inlined. If too few or too many
functions are inlined, consider using -qipa=inline or -qipa=noinline.
To control inlining of specific functions, use -qipa=[no]inline=function_name.
- To generate data reorganization information in the
listing file, specify the optimization level -qipa=level=2 or -O5 together
with -qreport. During the IPA link pass, the data
reorganization messages for program variable data will be produced
to the data reorganization section of the listing file with the label DATA
REORGANIZATION SECTION. Reorganizations include array splitting,
array transposing, memory allocation merging, array interleaving,
and array coalescing.
- Use -r -qipa=relink to
create a nonexecutable package that contains all of your object files
while preserving IPA information. If you want to use your archive
files while generating the package, you can use the ar tool
and set the XL_AR environment variable to point
to the ar tool. For details, refer to the -qipa section
of the XL C/C++ Compiler
Reference.
Note: While IPA's interprocedural optimizations
can significantly improve performance of a program, they can also
cause incorrect but previously functioning programs to fail. Here
are examples of programming practices that can work by accident without
aggressive optimization but are exposed with IPA:
- Relying on the allocation order or location of automatic variables,
such as taking the address of an automatic variable and then later
comparing it with the address of another local variable to determine
the growth direction of a stack. The C language does not guarantee
where an automatic variable is allocated, or its position relative
to other automatic variables. Do not compile such a function with
IPA.
- Accessing a pointer that is either invalid or beyond an array's
bounds. Because IPA can reorganize global data structures, a wayward
pointer which might have previously modified unused memory might now
conflict with user-allocated storage.