[PATCH] D26370: Use max(BFI_Count, TotalProfCount) to get block's profile count.

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 13:53:17 PST 2016


danielcdh abandoned this revision.
danielcdh added a comment.

As discussed with David offline:

- Adding this to the BFI interface is too hacky
- The perfect solution would be improve samplepgo branch_probability propagation algorithm:
  - The algorithm takes BB->count map (for a subset of all BBs in the function) as input, and output the Edge->probability map
  - The current algorithm uses iterative solution to infer branch probability from BB counts. It is guaranteed to converge in a few iterations (fast), but it's adhoc, and does not guarantee flow-consistency (i.e. sum(in-edge-weights) = sum(out-edge-weights)). As a result, Applying BFI on the computed branch probability can lead to incorrect BB count (comparing with the input BB->count map).
  - To ensure flow consistency, MCF needs to be used, which is super expensive (We initially experimented with it in GCC, and finally gave up).
  - A new adhoc algorithm needs to be designed to derive reasonably accurate branch probability while ensuring hot BB counts computed by BFI agrees with the original BB count map. It seems very difficult to design such an algorithm as there are a lot to consider in the propagation, e.g.
    1. missing BB count in the original input
    2. 0 sample count for function/loop entry
    3. loop early-exit and irregular control flow
- As we do not have a clear picture towards how to design a perfect propagation algorithm, we can use the extracProfTotalWeights to get the original counts from metadata for now. But we need to make sure that the branch probability metadata gets updated by optimizations that would clone code, especially function inlining. And also, we need to move the logic to a helper function in PSI instead of a public API in BFI.

So I will close this patch for now, and move the changes to  https://reviews.llvm.org/D26353


https://reviews.llvm.org/D26370





More information about the llvm-commits mailing list