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
Yes, since it turns into a branch instruction where one path falls through and the other jumps somewhere. If it jumps up to a block above, it looks like a loop. If it jumps down, that looks like a jump to a cold path so the fall through looks hotter. It's just implicit hints.
1
1
Replying to and
There are usually not actually explicit branch predictor hints but there is a lot of implicit information and the compiler knows how to align, order and group things to help the branch predictor, etc. Some of it depends on CPU generation so targeting specific CPU can help a bit.
2
Replying to and
It can ramp up unrolling, vectorization, inlining, etc. for hot cold and not only avoid it but heavily optimize cold code for size, etc. LLVM barely does some of these things, but it could, and is getting better. It's really not as smart as you would probably expect it to be.
1
Replying to and
In practice, there are only about a dozen places where this kind of metadata is taken into account but they're very important places. The main thing that makes it more disappointing than it should be is a lot of optimization passes are bad at preserving this kind of metadata.
1
Show replies