Conversation

Is there a document somewhere that describes what optimizations PGO opens up? Like I imagine it can say "don't inline this, it doesn't get called" and "inline this, it gets called a bunch", but what else?
1
2
Replying to
It provides branch metadata so it knows how to order branches or add hints for better branch prediction. Can also decide when to use cmov, etc. that way. Since it has metadata on function call sites, callees and branches it can also split out functions into hit/cold regions, etc.
2
Replying to
Is there a doc with all of this? I actually don't even know how code tells a branch predictor "this is the likely branch", although I know that gcc had a 'likely' builtin iirc. I see you mentioned a builtin, I'll check that out too.
1
Replying to and
__builtin_expect_with_probability allows you to specify the probability yourself instead of having a standard default. __attribute__((cold)) and __attribute__((hot)) are relevant too, and the compilers will usually infer that a branch calling a cold function is itself cold, etc.
1
Replying to and
Getting branch metadata for ordering the branches is one of the most important parts of PGO since branch predictors heavily use the order of branches. They can also output certain kinds of hints. The rest is largely knowing which blocks / functions are hot and how to group them.
1
1
Replying to and
Inlining and partial inlining can also use that information on code hotness and where it's called from too. You can get the benefits through manual optimization but you may need to do partial inlining, etc. yourself because you can't communicate all of the metadata manually.
1