What information does GCC Profile Guided Optimization (PGO) collect and which optimizations use it?
Asked Answered
B

2

48

Which information does GCC collect when I enable -fprofile-generate and which optimization does in fact uses the collected information (when setting the -fprofile-use flag) ?

I need citations here. I've searched for a while but didn't found anything documented.

Information regarding link-time optimization (LTO) would be a plus! =D

Benevolent answered 14/12, 2012 at 15:10 Comment(0)
P
46

-fprofile-generate enables -fprofile-arcs, -fprofile-values and -fvpt.

-fprofile-use enables -fbranch-probabilities, -fvpt, -funroll-loops, -fpeel-loops and -ftracer

Source: http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Optimize-Options.html#Optimize-Options

PS. Information about LTO also on that page.

Prerogative answered 14/12, 2012 at 15:22 Comment(1)
I just arrived at the same link. Thanks anyway.Benevolent
O
20

"What Every Programmer Should Know About Memory" by Ulrich Drepper https://people.freebsd.org/~lstewart/articles/cpumemory.pdf http://www.akkadia.org/drepper/cpumemory.pdf

In section 7.4

  • compilation with --profile-generate generates .gcno file for each object file. (the same file that is used for gcov coverage reports)
  • then you must run a few tests, during runtime it records coverage data into .gcda files
  • recompile with --profile-use : it will gather the coverage data and infer if an branch is likely (__builtin_expect( .. , 1 ) or unlikely (__builtin_expect( .. , 0)

The result should run faster as it should be better at prefetching code into the processor instruction cache.

Overage answered 20/12, 2015 at 10:14 Comment(1)
In my case the same (fully deterministic, computation-heavy) program used to generate the profile became slower after using this profile (compared to compilation without any profiling). So don't expect magical enhancement of performance in every case.Gulfweed

© 2022 - 2024 — McMap. All rights reserved.