[PATCH] D31085: [InlineCost] Increase the cost of Switch
Haicheng Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 20 08:48:57 PDT 2017
haicheng added inline comments.
================
Comment at: lib/Analysis/InlineCost.cpp:1051
+
+ while (!SwitchWorkList.empty()) {
+ unsigned NumCases = SwitchWorkList.back();
----------------
haicheng wrote:
> hans wrote:
> > Why do we have to do this?
> >
> > The code is basically constructing the tree and throwing it away. It should be possible to compute an estimate for the size of the tree with a closed-form mathematical expression.
>
> If n is the case number, f(n) is the mapping from the case number to the node number of BTree. The recursion is
> f(n) = 1 + f(n/2) + f (n - n/2), when n > 3.
> So, f(n) is between n + 2^(log2(n) - 1) - 1 and n + 2^(log2(n)) - 1. The lower bound is about 1.5n - 1 and the upper bound is about 2n - 1
The exact equation is
f(n) = n, n <= 3
f(n) = n + 2^(log(n) - 1) - 1, n > 3 && 2^log(n) <= n <= 1.5*2^(log(n))
f(n) = 2n - 2^(log(n)) - 1, n > 3 && 1.5*2^(log(n)) < n < 2^(log(n)+1)
https://reviews.llvm.org/D31085
More information about the llvm-commits
mailing list