How do you use PGO + LTO optimization with GCC
<p>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.</p>

<p>I've been reading to compile with the flags </p>

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

<p>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)</p>

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

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

<p>Question: </p>

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