3 ms·
PGO is pretty difficult. In my experience compilers don't seem to know the difference between "this thing never runs" and "we don't have any information about i
by astrange 2y ago
PGO is pretty difficult. In my experience compilers don't seem to know the difference between "this thing never runs" and "we don't have any information about if this thing runs". Similarly it might be useful to know "is this branch predictable" more than just "what % is it taken".
CPUs are so dynamic anyway that there often isn't a way to pass down the information you'd get from the profile. eg I don't think Intel actually recommends any way of hinting branch directions.
- jeffbee 2y agoIt's implied by the target offset. Taken branches jump backwards, unlikely branches jump forward.
- saagarjha 2y agoSurely you are not putting code behind an if/else
- atq2119 2y agoNot generally, no. This is true for some chips, especially (very) old or simple cores, but it's not something to lean on for modern high end cores.
- jeffbee 2y agoGenerally yes. This is not for "simple" cores this is the state-of-the-art static branch prediction algorithm as described by Intel in their optimization manual. "Branches that do not have a history in the BTB ... are predicted using a static prediction algorithm: Predict forward conditional branches to be NOT taken. Predict backward conditional branches to be taken." It then goes on to recommend exactly what every optimizing compiler and post-link optimizers like BOLT do: "Arrange code to be consistent with the static branch prediction algorithm: make the fall-through code following a conditional branch be the likely target for a branch with a forward target, and make the fall-through code following a conditional branch be the unlikely target for a branch with a backward target." This is why a reduction in taken forward branches is one of the key statistics that BOLT reports.