[PATCH] D93838: [LLVM] [SCCP] : Add Function Specialization pass
Chuanqi Xu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 13 05:09:49 PDT 2021
ChuanqiXu added inline comments.
================
Comment at: llvm/lib/Transforms/Scalar/SCCP.cpp:2577
+ // already be constant.
+ if (!Solver.getLatticeValueFor(A).isOverdefined())
+ return false;
----------------
Joe wrote:
> What if the LatticeValue is a ConstantRange? There could be some great specialization opportunities there. Currently, only checking for overdefined leads to:
>
> ```
>
> // specialized
> foo(a)
> foo(1)
> foo(2)
>
> // not specialized
> foo(1)
> foo(2)
> foo(3)
> ```
ConstantRange seems to be a much more complex problem. We need analysis for Function to calculate/model the benefit if we can know the range information for some arguments.
Then how do we handle the range is another problem. For example, if there is a range [0, 100] for argument `a` of function foo, the best specialization solution maybe specialize foo into foo_1 and foo_2. Then all the call site with argument in [0, 50) should call foo_1 and all the call site with argument in [50, 100] should call foo_2. But how can we find the best split point?
My point is, it may not be a good solution to specialize the function if we find constant range. I prefer to handle this in successive patch.
================
Comment at: llvm/lib/Transforms/Scalar/SCCP.cpp:2588
+ if (PossibleConstants.empty() ||
+ PossibleConstants.size() > MaxConstantsThreshold)
+ return false;
----------------
Joe wrote:
> The major problem I see with a simple cutoff threshold like this would be the following:
>
> 10x foo(a)
> 1x foo(b)
> 1x foo(c)
> 1x foo(d)
>
> There could be huge benefit for specializing for foo(a) here. A potential change here I see is for PossibleConstants to capture the number of occurrences (possibly taking into account loops), and to specialize the function up to MaxConstantsThreshold in descending count order.
It may be a good idea to consider the occurrences into cost model. Then the example shows potential for using profiling info in function specialization pass.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93838/new/
https://reviews.llvm.org/D93838
More information about the llvm-commits
mailing list