6
votes

I have a set of static libraries, say lib1.a, lib2.a and lib3.a which have been compiled using ICC (Intel C/C++ Compiler). I used ICC with -ipo -c for compilation to create .o files and then XIAR (Intel Archiver) for creating .a libraries.

I want to give these three libraries to a client who does not have ICC and hence will be using GCC to compile and link her application with these libraries. Will the speed-gain (expected from cross-file optimizations due to libs built with -ipo option) not be achieved at all if she links these libraries using GCC?

This page from Intel Website on "GCC Compatibility and Interoperability" states:

Link-time optimization using the -ffat-lto-objects compiler option is provided for gcc compatibility. This implies that ld and ar can be used to link and archive object files, but by doing so you will lose cross-file optimizations.

I am using icc version 13.1.0 (gcc version 4.6.0 compatibility) with gcc version 4.6.3 on Ubuntu 12.04.2.

Any help will be appreciated.

2

2 Answers

3
votes

If you using -ipo the optimization will actually happen at the link stage.

During compilation (icc -c -ipo) the Intel compiler only stores additional information in the object files. This additional information is used at link stage to do the actual interprocedural optimization (ipo).

So in order to benefit from IPO you need to use the Intel compiler at compile and link stage.

1
votes

If you created the archive with xiar, then all the objects you want placed in the archive are compiled together using IPO and put into your static library. You'll end up with a real .a file that is optimized with -ipo.

You CAN give that library to anyone, and they will get the benefit of having the library itself cross compiled with -ipo, but the library code will not be mixed in other libraries of the users objects with which it's being linked.

Basically, you'll have a .a file that is fully optimized with -ipo (assuming all the objects in it were built with -ipo) that you can give to clients. The clients code will not "further" optimize with -ipo against your library.