How do you use PGO + LTO optimization with GCC

2.6k views Asked by At

I've been researching a lot lately on how PGO and LTO can significantly optimize a programs speed (some say around 20%). I currently just program in C and build GUI's with GTK+ in Windows (compiling everything through GCC) and only use -O2 for optimization.

I've been reading to compile with the flags

gcc -Wall -g -mwindows -O3 -fprofile-generate -flto example.c -o example.exe `pkg-config --cflags --libs gtk+-3.0`

a .gcno and a .gcda file is created, then you run the compiled .exe a bunch of times then just re-compile the same .c file again but swap the "-fprofile-generate" with "-fprofile-use"? (while making sure all these files stay in the same folder/directory, and use a different name for the .exe compiled the second time)

gcc -Wall -g -mwindows -O3 -fprofile-use -flto example.c -o program.exe `pkg-config --cflags --libs gtk+-3.0`

Or do you make use of the .gcno/.gcda file somehow? Also read things about using a "benchmark".

Question:

What are the steps to use it in GCC? (Step by step guide would help :)

0

There are 0 answers