On Fri, Feb 22, 2013 at 3:08 PM, Easwaran Raman <[email protected]> wrote:
> Hi,
>
> Consider the following function
>
> A *CheckNotNull (A *a_ptr) {
> if (a_ptr == NULL) {
> // Code with non-trivial code size
> }
> return a_ptr;
> }
>
> If this is invoked as CheckNotNull(&a), the inliner should be able to
> infer that (a_ptr == 0) predicate is false and estimate the size and
> time based on that. For this to happen, there should be a way to
> specify that the parameter is non-NULL. Is it reasonable to replace
> trees corresponding to IPA_JF_CONST with a value_range and encode
> non-NULL as an anti_range?
I think this will be useful. Function splitting/outliining may or may
not happen for this case, making inline size estimation smarter is a
good way to go. Also consider the following scenario
(interprprocedural VRP:
int foo (int a)
{
if (a > 0)
{
...
}
...
}
int bar ()
{
if (a > 9) {
foo (a) ; // more precise size estimation.
....
}
else
{
foo (a + 1);
}
...
}
More generally, can the following be handled?
nt foo (int a, int b)
{
if (a > b)
{
...
}
...
}
int bar ()
{
if (a > b) {
foo (a, b) ; // more precise size estimation.
....
}
else
{
foo (b, a);
}
...
}
>
> This would mean that ipa-cp versions can not be created by just
> initializing the parameter with the propagated constant. This leads to
> another thought: Versioning of functions based on values may not be
> ideal in the context of cloning. Consider a similar function:
>
> int foo (int n) {
> if (n == 0)
> {
> // Non-trivial amount of code
> }
> // Some more code, but no/few expressions involving N and a constant.
> }
>
> If ipa-cp-clone is on, we might end up with many clones for foo for
> different non-zero values for N. Instead, it may be beneficial to
> create just a single foo.non_zeroN and reap most of the benefits of
> cloning. Cloning could be done primarily based on the number of
> predicates of the function that are true at the call site. (Doing so
> might also help avoid putting clone of comdats as file-locals as one
> could generate the clone name based on the predicate and put in its
> comdat group. )
>
> Are these worth pursuing?
>
IMO, yes. The more context you can pass to the callee for inline/clone
benefit/cost analysis, the better. Other things include alias info,
alignment info etc.
David
> Thanks,
> Easwaran