Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone have experience with gcc's LTO (C++)?

Tags:

c++

gcc

My main interest is with moving code from header files to source files (for decoupling), but keeping the same performance for the inlined stuff.

I'm not sure where to get started, could someone explain what to do?

like image 356
Yuval Avatar asked Dec 09 '09 18:12

Yuval


People also ask

Does LTO improve performance?

LTO provides a performance boost for all the compilers. With small projects, this boost probably wouldn't be noticeable, but for big ones this option definitely makes a difference.

Should I use link time optimization?

Generally speaking, you should not use Link Time Optimization for Crypto++. There are three reasons for the recommendation. First, we don't want the linker changing object files or the executables produced during link. The linker's job is to combine object files, not attempt to peephole optimize them.

What does link time optimization do?

Link Time Optimization is a form of interprocedural optimization that is performed at the time of linking application code. Without LTO, Arm® Compiler for Linux compiles and optimizes each source file independently of one another, then links them to form the executable.

How do I enable LTO?

This is basically the set in the link above: To enable LTO, follow these simple steps: Add option -flto to the invocation of compiler. Add option -flto to the invocation of the linker. Additionally, you need to add all options from the compiler invocations to the invocation of the linker.


2 Answers

I did some testing on Firefox and LTO showing memory use, compile times and runtimes At my blog also comparing with LLVM. LTO is quickly developing, GCC 4.9 fares considerably better than previous releases. It is not always obvious how to get it working right for a given application, the text describes the main problems you can encounter (lack of linker plugin, using fat LTO files and throwing away the LTO part at link and others)

like image 110
Jan Hubička Avatar answered Oct 03 '22 00:10

Jan Hubička


We have made very limited experiments. In our case, performance gains where quite neglictible, but as we had already taken care of having good inlining, that's not extremely surprising.

However, enabling LTO incurred a huge increase in GCC's memory consumption, basically making parallel compilation impossible on our 4 CPU / 4 GB developpement machines, so we suspending the experiment and are waiting for future versions to try again.

like image 27
Zorglub Avatar answered Oct 02 '22 23:10

Zorglub