[CSSPGO] Overwrite branch weight annotated in previous pass.

Authored by hoy on May 16 2021, 11:13 PM.


[CSSPGO] Overwrite branch weight annotated in previous pass.

Sample profile loader can be run in both LTO prelink and postlink. Currently the counts annoation in postilnk doesn't fully overwrite what's done in prelink. I'm adding a switch (-overwrite-existing-weights=1) to enable a full overwrite, which includes:

  1. Clear old metadata for calls when their parent block has a zero count. This could be caused by prelink code duplication.
  1. Clear indirect call metadata if somehow all the rest targets have a sum of zero count.
  1. Overwrite branch weight for basic blocks.

With a CS profile, I was seeing #1 and #2 help reduce code size by preventing post-sample ICP and CGSCC inliner working on obsolete metadata, which come from a partial global inlining in prelink. It's not expected to work well for non-CS case with a less-accurate post-inline count quality.

It's worth calling out that some prelink optimizations can damage counts quality in an irreversible way. One example is the loop rotate optimization. Due to lack of exact loop entry count (profiling can only give loop iteration count and loop exit count), moving one iteration out of the loop body leaves the rest iteration count unknown. We had to turn off prelink loop rotate to achieve a better postlink counts quality. A even better postlink counts quality can be archived by turning off prelink CGSCC inlining which is not context-sensitive.

Reviewed By: wenlei, wmi

Differential Revision: https://reviews.llvm.org/D102537


hoyMay 19 2021, 9:12 AM
Differential Revision
D102537: [CSSPGO] Overwrite branch weight annotated in previous pass.
rG517857421d2f: Revert "Do actual DCE in LoopUnroll (try 3)"