Questions about Profile Guided Optimization (PGO)

Hello, All,

I am studying the optimizations adopted by LLVM, and finding PGO, which is said to be a good helper for optimization.

Since that requires to instrument and execute the object program, which may be costly for compilation and sometimes inconvenient for developers to come up with test cases, I wonder whether it is a default option for the compilation (i.e., when -O2 or -O3 is enabled)?

If that is the case, how LLVM generates test cases for the profiling if no tests are provided?

If PGO is default and there are no test cases, does LLVM estimate the profiling information, such as frequencies of bbs or calls, statically?

Thanks for your time.

Sincerely,

Reixiong Hu

Hi,

It kind of depends on how you define what PGO consists of. But, let’s not get stuck on terminology. Basically, if you provide profiling information, then LLVM will take
them into account by default. If not, yes, it will use static heuristics. However, that doesn’t necessarily mean that it will estimate frequencies because a lot of times the code looks like this:
if (there is profiling information) {
use a heuristic which is based on frequencies
} else {
use a heuristic based on other things (e.g., the structure of the code)
}

i.e., the else part is not necessarily “else estimate frequencies and use the same heuristic as if there were”

Best,
Stefanos

Στις Δευ, 28 Ιουν 2021 στις 4:30 π.μ., ο/η Reixiong Hu via llvm-dev <llvm-dev@lists.llvm.org> έγραψε:

Hello, Stefanos,

Got it. Thanks for the comprehensive answer.

Sincerely,

Yikun Hu