[PATCH] D93838: [LLVM] [SCCP] : Add Function Specialization pass
Joseph Faulls via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 13 06:11:24 PDT 2021
Joe added inline comments.
================
Comment at: llvm/lib/Transforms/Scalar/SCCP.cpp:2577
+ // already be constant.
+ if (!Solver.getLatticeValueFor(A).isOverdefined())
+ return false;
----------------
ChuanqiXu wrote:
> 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.
Absolutely, I agree that this can be handled well in a successive patch. However, seeing as it currently doesn't specialize for more than MaxConstantsThreshold, can't we just have a naive implementation that specializes for all the constant range given it's small enough? It just seems odd to me that it won't specialize foo(1) and foo(2).
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