[all-commits] [llvm/llvm-project] 4ca6e3: [CSSPGO] Overwrite branch weight annotated in prev...

Hongtao Yu via All-commits all-commits at lists.llvm.org
Wed May 19 09:26:09 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4ca6e37b9825db6d27a0aa2311b6530ac3faf021
      https://github.com/llvm/llvm-project/commit/4ca6e37b9825db6d27a0aa2311b6530ac3faf021
  Author: Hongtao Yu <hoy at fb.com>
  Date:   2021-05-19 (Wed, 19 May 2021)

  Changed paths:
    M llvm/lib/Transforms/IPO/SampleProfile.cpp
    M llvm/test/Transforms/SampleProfile/branch.ll
    A llvm/test/Transforms/SampleProfile/pseudo-probe-profile-metadata-2.ll

  Log Message:
  -----------
  [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.

2. Clear indirect call metadata if somehow all the rest targets have a sum of zero count.

3. 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




More information about the All-commits mailing list