[PATCH] [PGO] Hoist hot case statement from switches

Hans Wennborg hans at chromium.org
Mon Mar 30 19:26:16 PDT 2015


In http://reviews.llvm.org/D5786#149384, @silvas wrote:

> In http://reviews.llvm.org/D5786#149001, @hans wrote:
>
> > The direction I'd like to explore with my patch however, is to balance the binary tree based on profile info rather than node count. That would put hotter cases closer to the root. If f(x) is the number of branches needed to reach case x, I think this approach would minimize the expected value of f(x) when x is a random variable with a distribution matching the profile info.
>
>
> Sort of random, but in case it saves you a bunch of time, I believe this exact problem is covered in Knuth (either volume 1 or 3, I forget). The keyword is "optimal binary search tree".


Thanks! It sounds like what I'm proposing is this approach: http://en.wikipedia.org/wiki/Optimal_binary_search_tree#Mehlhorn.27s_approximation_algorithm

I guess it was bold of me to claim my idea guarantees the minimum expected value, but this makes me think it's still a good idea.


http://reviews.llvm.org/D5786

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list