If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis.
So my question here is: what kind(s) of precision really justify the cost and what kinds do not? Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?
Hi Jia,
If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis.
For at least some published AA algorithms, there may be some uncertainty about software patents and/or copyright.
At one point I was interested in the status of this AA implementation by Lian Li et al. IIRC, when I contacted Lian to ask if there was any chance of getting it into LLVM, IIRC she said that her employer wouldn't promise to relinquish all possible claims it had on that algorithm's IP. So unfortunately, at least in the U.S., an algorithm being published in an academic journal doesn't remove all legal risk associated with using it.
Also, speaking from my own experience, even when an AA algorithm seems to be described in great detail in some piece of literature (e.g., a phd thesis), there can still be a lot of details which are glossed over, or which seem clear when reading the document but which get a lot more confusing when one tries to actually implement it.
That can make implementing such an algorithm take far longer than one would expect based on just reading the document. (It's also an argument in favor of requiring academic papers which describe the behavior of a software implementation to actually include a working copy of the source code, IMHO.)
So my question here is: what kind(s) of precision really justify the cost and what kinds do not? Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?
At one point I discussed this with Daniel Berlin, but I'm having trouble find a record of the conversation. IIRC, he says that he once threw a huge amount of computing power at doing a full context-sensitive AA on some software, and the speedup he observed in the resulting program as underwhelming (10-15%?).
I can't remember if that was with GCC or LLVM. That result is a data point, although it may not say much about how much additional speedup could be realized if the algorithms which use the AA results were themselves adapted to capitalize on fully context-sensitive, flow-sensitive, hula-dancer-on-the-dashboard AA results.
Cheers,Christian
Dear llvm devs,
tl;dr: What prevents llvm from switching to a fancier pointer analysis?
Currently, there exists a variety of general-purpose alias analyses in the LLVM codebase: basic-aa, globalsmodref-aa, tbaa, scev-aa, and cfl-aa. However, only the first three are actually turned on when invoking clang with -O2 or -O3 (please correct me if I'm wrong about this).
If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis. Some are field-sensitive, some are field-based, some are flow-sensitive, some are context-sensitive. Even for flow-insensitive ones, they could also be inclusion-style (-andersen-aa) and equality-style (-steens-aa and -ds-aa). Those algorithms are often backed up by rich theoretical framework as well as preliminary evaluations which demonstrate their superior precision and/or performance.
Given such an abundance choices of pointer analyses that seem to be much better in the research land, why does real-world compiler infrastructures like llvm still rely on those three simple (and ad-hoc) ones to perform IR optimization?
Based on my understanding (and again please correct me if I am wrong):
(1) The minor reason: those "better" algorithms are very hard to implement in a robust way and nobody seems to be interested in trying to write and maintain them.
(2) The major reason: it's not clear whether those "better" algorithms are actually better for llvm. More precise pointer analyses tend to slow down compile time a lot while contributing too little to the optimization passes that use them. The benefit one gets from a more precise analysis may not justify the compile-time or the maintenance cost.
So my question here is: what kind(s) of precision really justify the cost and what kinds do not?
Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?
Could there potentially be more improvement on pointer analysis precision without adding too much compile-time/maintenance cost?
Has the precision/performance tradeoffs got fully explored before?
Any pointers will be much appreciated. No pun intended :)
PS1: To be more concrete, what I am looking for is not some black-box information like "we switched from basic-aa to cfl-aa and observed 1% improvement at runtime". I believe white-box studies such as "the licm pass failed to hoist x instructions because -tbaa is not flow sensitive" are much more interesting for understanding the problem here.
PS2: If no such evaluation exists in the past, I'd happy to do that myself and report back my findings if anyone here is interested.
Hi Jia,If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis.For at least some published AA algorithms, there may be some uncertainty about software patents and/or copyright.At one point I was interested in the status of this AA implementation by Lian Li et al. IIRC, when I contacted Lian to ask if there was any chance of getting it into LLVM, IIRC she said that her employer wouldn't promise to relinquish all possible claims it had on that algorithm's IP. So unfortunately, at least in the U.S., an algorithm being published in an academic journal doesn't remove all legal risk associated with using it.
Also, speaking from my own experience, even when an AA algorithm seems to be described in great detail in some piece of literature (e.g., a phd thesis), there can still be a lot of details which are glossed over, or which seem clear when reading the document but which get a lot more confusing when one tries to actually implement it.
That can make implementing such an algorithm take far longer than one would expect based on just reading the document. (It's also an argument in favor of requiring academic papers which describe the behavior of a software implementation to actually include a working copy of the source code, IMHO.)
So my question here is: what kind(s) of precision really justify the cost and what kinds do not? Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?At one point I discussed this with Daniel Berlin, but I'm having trouble find a record of the conversation. IIRC, he says that he once threw a huge amount of computing power at doing a full context-sensitive AA on some software, and the speedup he observed in the resulting program as underwhelming (10-15%?).
I can't remember if that was with GCC or LLVM. That result is a data point, although it may not say much about how much additional speedup could be realized if the algorithms which use the AA results were themselves adapted to capitalize on fully context-sensitive, flow-sensitive, hula-dancer-on-the-dashboard AA results.
Hi Daniel,
On 03/21/2016 11:05 AM, Daniel Berlin wrote:
On Tue, Mar 15, 2016 at 1:37 PM, Jia Chen via llvm-dev <llvm...@lists.llvm.org> wrote:
Dear llvm devs,
tl;dr: What prevents llvm from switching to a fancier pointer analysis?
Nothing.
Currently, there exists a variety of general-purpose alias analyses in the LLVM codebase: basic-aa, globalsmodref-aa, tbaa, scev-aa, and cfl-aa. However, only the first three are actually turned on when invoking clang with -O2 or -O3 (please correct me if I'm wrong about this).
This is correct.Eventually, i hope george will have time to get back to CFL-AA and turn it on by default.
If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis. Some are field-sensitive, some are field-based, some are flow-sensitive, some are context-sensitive. Even for flow-insensitive ones, they could also be inclusion-style (-andersen-aa) and equality-style (-steens-aa and -ds-aa). Those algorithms are often backed up by rich theoretical framework as well as preliminary evaluations which demonstrate their superior precision and/or performance.
CFL-AA is a middle ground between steens and anders, can be easily made field and context sensitive, etc.
Given such an abundance choices of pointer analyses that seem to be much better in the research land, why does real-world compiler infrastructures like llvm still rely on those three simple (and ad-hoc) ones to perform IR optimization?
Time and energy.
Based on my understanding (and again please correct me if I am wrong):
(1) The minor reason: those "better" algorithms are very hard to implement in a robust way and nobody seems to be interested in trying to write and maintain them.
This is false. Heck, at the time i implemented it in GCC, field-sensitive andersen's analysis was unknown in production compilers. That's why i'm thanked in all the papers - i did the engineering work to make it fast and reliable.
(2) The major reason: it's not clear whether those "better" algorithms are actually better for llvm. More precise pointer analyses tend to slow down compile time a lot while contributing too little to the optimization passes that use them. The benefit one gets from a more precise analysis may not justify the compile-time or the maintenance cost.
CFL-AA is probably the right trade-off here. You can stop at any time and have correct answers, you can be as lazy as you like.etc.
Regarding CFL-AA: in my understanding, cfl-aa does not introduce a new precision tradeoff.
It is merely a demand-driven way of implementing existing analyses, by extending those algorithms to track additional "pointed-to-by" information. Laziness may help with the running time of the cfl analysis when only partial points-to info is needed, but if the client wants to do a whole-program analysis and require whole-program points-to info (which is usually true for optimizing compilers since they will eventually examine and touch every piece of the codes given to it), should cfl-aa be no different than traditional whatever-sensitive pointer analysis?
The reality is i think you overlook the realistic answer:
3. Nobody has had time or energy to fix up CFL-AA or SCEV-AA. They spend their time on lower-hanging fruit until that lower hanging fruit is gone.
IE For the moment, CFL-AA and SCEV-AA and ... are not the thing holding llvm back.
I'd love to hear some examples of "lower-hanging fruit" in LLVM, especially in the area of middle-end analyses and optimizations. I thought LLVM is mature enough that any obvious chances of improvement in analyses and optimization have already been taken, no?
So my question here is: what kind(s) of precision really justify the cost and what kinds do not?
Depends entirely on your applications.Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?Yes.Chris did many years ago, and i've done one more recently.
Great! Are they published somewhere? Can the data be shared somehow?
Could there potentially be more improvement on pointer analysis precision without adding too much compile-time/maintenance cost?Yes.
Has the precision/performance tradeoffs got fully explored before?
Yes
Any pointers will be much appreciated. No pun intended :)
PS1: To be more concrete, what I am looking for is not some black-box information like "we switched from basic-aa to cfl-aa and observed 1% improvement at runtime". I believe white-box studies such as "the licm pass failed to hoist x instructions because -tbaa is not flow sensitive" are much more interesting for understanding the problem here.
White-box studies are very application specific, and often very pass specific.
And I understand that. My goal is to look for commonalities among passes and applications.
However, if the existing studies you mentioned above are extensive and conclusive enough to show that the aas we have today have fully exploited almost all such commonalities, then it's probably a better idea for me to find something else to work on. But again, I'd like to see the data first.
PS2: If no such evaluation exists in the past, I'd happy to do that myself and report back my findings if anyone here is interested.I don't think any of the world is set up to make that valuable.
Nothing takes advantage of context sensitivity, flow sensitivity, etc.
I agree that nothing takes advantage of context sensitivity. But I would argue against flow sensitivity, field sensitivity, heap model and external function models
. Flow sensitivity is helpful when the optimization pass itself is flow-sensitive (e.g. adce, gvn),
and field sensitivity is helpful when a struct contains multiple pointers. Heap sensitivity is basically what motivates Chris Lattner's PLDI'07 paper, and external function models are helpful since without them the analysis has to be extremely conservative and concludes everything that external functions touch all may-alias each other.
On Tue, Mar 15, 2016 at 1:37 PM, Jia Chen via llvm-dev <llvm...@lists.llvm.org> wrote:
Dear llvm devs,
tl;dr: What prevents llvm from switching to a fancier pointer analysis?
Nothing.
Currently, there exists a variety of general-purpose alias analyses in the LLVM codebase: basic-aa, globalsmodref-aa, tbaa, scev-aa, and cfl-aa. However, only the first three are actually turned on when invoking clang with -O2 or -O3 (please correct me if I'm wrong about this).
This is correct.Eventually, i hope george will have time to get back to CFL-AA and turn it on by default.
If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis. Some are field-sensitive, some are field-based, some are flow-sensitive, some are context-sensitive. Even for flow-insensitive ones, they could also be inclusion-style (-andersen-aa) and equality-style (-steens-aa and -ds-aa). Those algorithms are often backed up by rich theoretical framework as well as preliminary evaluations which demonstrate their superior precision and/or performance.
CFL-AA is a middle ground between steens and anders, can be easily made field and context sensitive, etc.
Given such an abundance choices of pointer analyses that seem to be much better in the research land, why does real-world compiler infrastructures like llvm still rely on those three simple (and ad-hoc) ones to perform IR optimization?
Time and energy.
Based on my understanding (and again please correct me if I am wrong):
(1) The minor reason: those "better" algorithms are very hard to implement in a robust way and nobody seems to be interested in trying to write and maintain them.
This is false. Heck, at the time i implemented it in GCC, field-sensitive andersen's analysis was unknown in production compilers. That's why i'm thanked in all the papers - i did the engineering work to make it fast and reliable.
(2) The major reason: it's not clear whether those "better" algorithms are actually better for llvm. More precise pointer analyses tend to slow down compile time a lot while contributing too little to the optimization passes that use them. The benefit one gets from a more precise analysis may not justify the compile-time or the maintenance cost.
CFL-AA is probably the right trade-off here. You can stop at any time and have correct answers, you can be as lazy as you like.etc.
The reality is i think you overlook the realistic answer:
3. Nobody has had time or energy to fix up CFL-AA or SCEV-AA. They spend their time on lower-hanging fruit until that lower hanging fruit is gone.
IE For the moment, CFL-AA and SCEV-AA and ... are not the thing holding llvm back.
So my question here is: what kind(s) of precision really justify the cost and what kinds do not?
Depends entirely on your applications.Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?Yes.Chris did many years ago, and i've done one more recently.
Could there potentially be more improvement on pointer analysis precision without adding too much compile-time/maintenance cost?
Yes.
Has the precision/performance tradeoffs got fully explored before?
Yes
Any pointers will be much appreciated. No pun intended :)
PS1: To be more concrete, what I am looking for is not some black-box information like "we switched from basic-aa to cfl-aa and observed 1% improvement at runtime". I believe white-box studies such as "the licm pass failed to hoist x instructions because -tbaa is not flow sensitive" are much more interesting for understanding the problem here.
White-box studies are very application specific, and often very pass specific.
PS2: If no such evaluation exists in the past, I'd happy to do that myself and report back my findings if anyone here is interested.I don't think any of the world is set up to make that valuable.
Nothing takes advantage of context sensitivity, flow sensitivity, etc.
This sounds like a good GSOC project.
Having the evaluation done is great, but if you can't share, than
that's pretty much useless to the community at large.
Even if a student does a less thorough evaluation, having something
out is better than having nothing, and with your expertise, I'm sure
we can get such a student doing some pretty capable analysis with
little resources.
cheers,
--renato
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
It is merely a demand-driven way of implementing existing analyses, by extending those algorithms to track additional "pointed-to-by" information. Laziness may help with the running time of the cfl analysis when only partial points-to info is needed, but if the client wants to do a whole-program analysis and require whole-program points-to info (which is usually true for optimizing compilers since they will eventually examine and touch every piece of the codes given to it), should cfl-aa be no different than traditional whatever-sensitive pointer analysis?
CFL, at least when I ran the numbers, was faster at all pairs than existing analysis.
Great! Are they published somewhere? Can the data be shared somehow?
No, and sadly, no
I'm talking about infrastructure wise, nothing in llvm can take advantage because the APIs don't exist.
. Flow sensitivity is helpful when the optimization pass itself is flow-sensitive (e.g. adce, gvn),
No api exists that they could use right now for this, and you'd have to change things to understand answers are not valid over the entire function.
On 21 March 2016 at 17:17, Daniel Berlin via llvm-dev <llvm...@lists.llvm.org> wrote:Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?Yes. Chris did many years ago, and i've done one more recently. Great! Are they published somewhere? Can the data be shared somehow?No, and sadly, noThis sounds like a good GSOC project.
On 21 March 2016 at 17:17, Daniel Berlin via llvm-dev
<llvm...@lists.llvm.org> wrote:
>>> Has anybody done any study in the past to evaluate what kinds of features
>>> in pointer analyses will benefit what kinds of optimization passes?
>>
>> Yes.
>> Chris did many years ago, and i've done one more recently.
>>
>> Great! Are they published somewhere? Can the data be shared somehow?
>
> No, and sadly, no
This sounds like a good GSOC project.
Having the evaluation done is great, but if you can't share, than
that's pretty much useless to the community at large.
Even if a student does a less thorough evaluation, having something
out is better than having nothing, and with your expertise, I'm sure
we can get such a student doing some pretty capable analysis with
little resources.
It is merely a demand-driven way of implementing existing analyses, by extending those algorithms to track additional "pointed-to-by" information. Laziness may help with the running time of the cfl analysis when only partial points-to info is needed, but if the client wants to do a whole-program analysis and require whole-program points-to info (which is usually true for optimizing compilers since they will eventually examine and touch every piece of the codes given to it), should cfl-aa be no different than traditional whatever-sensitive pointer analysis?
CFL, at least when I ran the numbers, was faster at all pairs than existing analysis.
There could be many reasons for it, e.g. better implementations.
Again, my point is that cfl-aa is more of an implementation strategy than a fundamentally superior approach.
I'm talking about infrastructure wise, nothing in llvm can take advantage because the APIs don't exist.
. Flow sensitivity is helpful when the optimization pass itself is flow-sensitive (e.g. adce, gvn),
No api exists that they could use right now for this, and you'd have to change things to understand answers are not valid over the entire function.
I see what you are saying now. Sometimes flow/ctx-insensitive alias queries can benefit from a flow/ctx-sensitive analysis, yet my intuition is that such cases are likely to be rare.
I could go ahead and modify those passes myself to carry on the study, but that option probably won't be too interesting to the community.
Thank you very much for pointing that out to me.
Makes sense. :)
> I would rather see someone spend their time getting SCEV-AA on by default or
> CFL-AA on by default than doing another evaluation.
But those may not be simple enough for a GSOC, that's why I mentioned it.
The analysis could not only get us a birds view of the problem ahead,
but also introduce new developers to AA, which would make their future
work on SCEV-AA or CFL-AA easier. Kind of a teaching tool to get more
AA-savvy people.
On 21 March 2016 at 18:59, Daniel Berlin <dbe...@dberlin.org> wrote:
> Which is why i've never mentioned it or used it in the community ;)
Makes sense. :)
> I would rather see someone spend their time getting SCEV-AA on by default or
> CFL-AA on by default than doing another evaluation.
But those may not be simple enough for a GSOC, that's why I mentioned it.
The analysis could not only get us a birds view of the problem ahead,
but also introduce new developers to AA, which would make their future
work on SCEV-AA or CFL-AA easier. Kind of a teaching tool to get more
AA-savvy people.
cheers,
--renato
From: "Daniel Berlin via llvm-dev" <llvm...@lists.llvm.org>
To: "Renato Golin" <renato...@linaro.org>, "George Burgess IV" <george.b...@gmail.com>
Cc: "llvm-dev" <llvm...@lists.llvm.org>, "Jia Chen" <jc...@cs.utexas.edu>
Sent: Monday, March 21, 2016 2:07:44 PM
Subject: Re: [llvm-dev] Existing studies on the benefits of pointer analysisOn Mon, Mar 21, 2016 at 12:05 PM, Renato Golin <renato...@linaro.org> wrote:On 21 March 2016 at 18:59, Daniel Berlin <dbe...@dberlin.org> wrote:
> Which is why i've never mentioned it or used it in the community ;)
Makes sense. :)
> I would rather see someone spend their time getting SCEV-AA on by default or
> CFL-AA on by default than doing another evaluation.
But those may not be simple enough for a GSOC, that's why I mentioned it.
CFL-AA should just be fixing performance regressions, and maybe a little bug fixing, which is hopefully easy enough. It's already fast enough as a pass.
SCEV-AA would be harder (must make SCEV-AA faster).The analysis could not only get us a birds view of the problem ahead,
but also introduce new developers to AA, which would make their future
work on SCEV-AA or CFL-AA easier. Kind of a teaching tool to get more
AA-savvy people.Sure.
cheers,
--renato
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
You can solve andersens and steengaards and everything else using standard dataflow solvers, and that's an implementation strategy, but it will be really slow.
Part of the tradeoff is how fast something runs, and approaches that are orders of magnitude faster often change the calculus of what people do. For example, before hardekopf's work, andersens was considered too slow to be practical in a real compiler.
Now, GCC does it by default.
So i would call that approach a superior approach :)
So saying that CFL-AA offers nothing superior in terms of approach, IMHO, misunderstands the nature of the problem. If your goal is to get precision at all costs, then yes, it's not superior. If your goal is to get something into a production compiler, that is understandable, maintainable, can turn on and off field and context sensitivity easily, etc, then it may be a superior approach.
Apparently "superior approach" is a misnomer on my side. My apologies.
What I should have said is "an approach with superior precision". Both cfl and Ben Hardekopf's work you mentioned (which improves analysis performance by using SSA transformation as a pre-pass to eliminate easy-to-analyze pointers)
can be viewed as optimizations on standard dataflow solver,
but at the end of the day they do nothing more than that.
From a client's perspective, they are no different from standard solvers except they are faster.
I do acknowledge that cfl may work better in practice (although I held different opinions about understandability and maintainability).
It's just that I tend to make judgment of pointer analysis based on the need of a client.
Again, I meant no offense and I apologize for my inappropriate choice of words.
I do acknowledge that cfl may work better in practice (although I held
different opinions about understandability and maintainability). It's
just that I tend to make judgment of pointer analysis based on the need
of a client. Again, I meant no offense and I apologize for my
inappropriate choice of words.
--
Best Regards,
--
Jia Chen
Hi Christian,
Thank you so much for the reply! Please see my comments inline.
On 03/21/2016 09:32 AM, Christian Convey wrote:
This is news to me. Thanks for sharing it.Hi Jia,
If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis.
For at least some published AA algorithms, there may be some uncertainty about software patents and/or copyright.
At one point I was interested in the status of this AA implementation by Lian Li et al. IIRC, when I contacted Lian to ask if there was any chance of getting it into LLVM, IIRC she said that her employer wouldn't promise to relinquish all possible claims it had on that algorithm's IP. So unfortunately, at least in the U.S., an algorithm being published in an academic journal doesn't remove all legal risk associated with using it.
My personal experience also coincides. And even if the paper does come with an artifact or source codes, they are usually proof-of-concept implementations with lots of important real-world corner cases ignored.
Also, speaking from my own experience, even when an AA algorithm seems to be described in great detail in some piece of literature (e.g., a phd thesis), there can still be a lot of details which are glossed over, or which seem clear when reading the document but which get a lot more confusing when one tries to actually implement it.
That can make implementing such an algorithm take far longer than one would expect based on just reading the document. (It's also an argument in favor of requiring academic papers which describe the behavior of a software implementation to actually include a working copy of the source code, IMHO.)
I kind of expect that. As you mentioned later, most optimization passes work in a context-insensitive manner (i.e. they won't clone a function and optimize differently on different clones). Context sensitivity on the pointer analysis side is probably not going to help a lot if the client cannot fully capitalize on it. In the settings of compiler optimization, my guess is that flow sensitivity, field sensitivity, heap model and external library annotations are the four aspects that are likely to matter.
So my question here is: what kind(s) of precision really justify the cost and what kinds do not? Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?
At one point I discussed this with Daniel Berlin, but I'm having trouble find a record of the conversation. IIRC, he says that he once threw a huge amount of computing power at doing a full context-sensitive AA on some software, and the speedup he observed in the resulting program as underwhelming (10-15%?).
I did some preliminary experiments with licm on c programs over the last weekend. I chose licm because intuitively that's the optimization that could have the biggest performance impact. The result suggested that tbaa, cfl-aa, scev-aa and globals-aa yields very little additional benefits over basic-aa. Again, both the methodology and benchmark selection are very immature and the results need to be double-checked, but my hope is that by looking at how aa algorithms and their clients interact I may be able to get some hints on what kind of aa a compiler really wants.
I can't remember if that was with GCC or LLVM. That result is a data point, although it may not say much about how much additional speedup could be realized if the algorithms which use the AA results were themselves adapted to capitalize on fully context-sensitive, flow-sensitive, hula-dancer-on-the-dashboard AA results.
Cheers,Christian
--
Best Regards,
--
Jia Chen
On 03/21/2016 08:56 AM, Jia Chen via llvm-dev wrote:
Hi Christian,Just to chime in here, your results match my experience and expectations with LICM as well. Between basic-aa, and TBAA (specifically LLVM's implementation thereof), I haven't seen a lot of cases where an imprecision in the alias analysis prevents hoisting.
Thank you so much for the reply! Please see my comments inline.
On 03/21/2016 09:32 AM, Christian Convey wrote:
This is news to me. Thanks for sharing it.Hi Jia,
If one looks at existing research literatures, there are even more algorithm to consider for doing pointer analysis.
For at least some published AA algorithms, there may be some uncertainty about software patents and/or copyright.
At one point I was interested in the status of this AA implementation by Lian Li et al. IIRC, when I contacted Lian to ask if there was any chance of getting it into LLVM, IIRC she said that her employer wouldn't promise to relinquish all possible claims it had on that algorithm's IP. So unfortunately, at least in the U.S., an algorithm being published in an academic journal doesn't remove all legal risk associated with using it.
My personal experience also coincides. And even if the paper does come with an artifact or source codes, they are usually proof-of-concept implementations with lots of important real-world corner cases ignored.
Also, speaking from my own experience, even when an AA algorithm seems to be described in great detail in some piece of literature (e.g., a phd thesis), there can still be a lot of details which are glossed over, or which seem clear when reading the document but which get a lot more confusing when one tries to actually implement it.
That can make implementing such an algorithm take far longer than one would expect based on just reading the document. (It's also an argument in favor of requiring academic papers which describe the behavior of a software implementation to actually include a working copy of the source code, IMHO.)
I kind of expect that. As you mentioned later, most optimization passes work in a context-insensitive manner (i.e. they won't clone a function and optimize differently on different clones). Context sensitivity on the pointer analysis side is probably not going to help a lot if the client cannot fully capitalize on it. In the settings of compiler optimization, my guess is that flow sensitivity, field sensitivity, heap model and external library annotations are the four aspects that are likely to matter.
So my question here is: what kind(s) of precision really justify the cost and what kinds do not? Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?
At one point I discussed this with Daniel Berlin, but I'm having trouble find a record of the conversation. IIRC, he says that he once threw a huge amount of computing power at doing a full context-sensitive AA on some software, and the speedup he observed in the resulting program as underwhelming (10-15%?).
I did some preliminary experiments with licm on c programs over the last weekend. I chose licm because intuitively that's the optimization that could have the biggest performance impact. The result suggested that tbaa, cfl-aa, scev-aa and globals-aa yields very little additional benefits over basic-aa. Again, both the methodology and benchmark selection are very immature and the results need to be double-checked, but my hope is that by looking at how aa algorithms and their clients interact I may be able to get some hints on what kind of aa a compiler really wants.
*However*, if you're interested in LICM specifically, I have *definitely* seen cases where the precision of AliasSetTracker (our grouping of AA results to prevent O(n^2) queries) prevents hoisting in spurious cases. AST could use some serious attention, both from an engineering standpoint and from (possibly) a theoretically one.
On Mon, Mar 21, 2016 at 6:28 PM, Philip Reames via llvm-dev <llvm...@lists.llvm.org> wrote:
On 03/21/2016 08:56 AM, Jia Chen via llvm-dev wrote:
Just to chime in here, your results match my experience and expectations with LICM as well. Between basic-aa, and TBAA (specifically LLVM's implementation thereof), I haven't seen a lot of cases where an imprecision in the alias analysis prevents hoisting.
I did some preliminary experiments with licm on c programs over the last weekend. I chose licm because intuitively that's the optimization that could have the biggest performance impact. The result suggested that tbaa, cfl-aa, scev-aa and globals-aa yields very little additional benefits over basic-aa. Again, both the methodology and benchmark selection are very immature and the results need to be double-checked, but my hope is that by looking at how aa algorithms and their clients interact I may be able to get some hints on what kind of aa a compiler really wants.
Yeah, at best, for LICM, it's just going to tell you the best place to insert runtime checks. LICM has a specific goal, and it's usually not AA that prevents proving something loop invariant. Most loads/stores are also either trivially loop invariant, or impossible to prove loop invariant.
*However*, if you're interested in LICM specifically, I have *definitely* seen cases where the precision of AliasSetTracker (our grouping of AA results to prevent O(n^2) queries) prevents hoisting in spurious cases. AST could use some serious attention, both from an engineering standpoint and from (possibly) a theoretically one.
You already know my view on this one: It's going to be remarkably hard to make AST work the way folks want it and have it be incremental and completely agnostic of anything but the AA API.
It's just really hard if not provably impossible to do this incrementally and avoid duplicate work, and get precise results and ...
On the other hand, it's pretty easy if you basically say "i provide list of all pointers and statements i care about, you make me some sets", and you let it figure out the answers upfront.
(it's also not clear to me why AST is the right abstraction for LICM to work on top of, but that's neither here nor there :P)
I think there's wide interest in getting CFL-AA into a usable state. As I recall, the percentage of noalias results during self hosting went up by a huge amount (for example). More noalias results obviously does not guarantee better code performance (the performance could even be worse because of register allocation / scheduling deficiencies). Nevertheless, we'll never do better if we're hamstrung by poor aliasing results.
Moreover, we currently rely heavily on BasicAA, which is a huge collection of local heuristics that catches many things, but is quite slow. It is slow because it needs to do local recursive walks for each pointwise query. If getting CFL-AA, in addition to increasing precision, provides us with a path away from our current BasicAA design toward something with better complexity, that's a definite win.
-Hal
So my question here is: what kind(s) of precision really justify the cost and what kinds do not?
Depends entirely on your applications.Has anybody done any study in the past to evaluate what kinds of features in pointer analyses will benefit what kinds of optimization passes?Yes.Chris did many years ago, and i've done one more recently.
Great! Are they published somewhere? Can the data be shared somehow?
I agree that nothing takes advantage of context sensitivity. But I would argue against flow sensitivity, field sensitivity, heap model and external function models. Flow sensitivity is helpful when the optimization pass itself is flow-sensitive (e.g. adce, gvn), and field sensitivity is helpful when a struct contains multiple pointers. Heap sensitivity is basically what motivates Chris Lattner's PLDI'07 paper, and external function models are helpful since without them the analysis has to be extremely conservative and concludes everything that external functions touch all may-alias each other.PS2: If no such evaluation exists in the past, I'd happy to do that myself and report back my findings if anyone here is interested.I don't think any of the world is set up to make that valuable.
Nothing takes advantage of context sensitivity, flow sensitivity, etc.
I’m still a big fan of context sensitive, flow insensitive, unification based models.
Contrary to your claim, context sensitivity *is* useful for mod-ref analysis, e.g. “can I hoist a load across this call”? Context sensitivity improves the precision of the mod/ref set of the call.
-Chris
I’m still a big fan of context sensitive, flow insensitive, unification based models.
Contrary to your claim, context sensitivity *is* useful for mod-ref analysis, e.g. “can I hoist a load across this call”? Context sensitivity improves the precision of the mod/ref set of the call.
> (This is actually why i'm a fan of CFL-AA. You can essentially make it
> as expensive or not expensive as you want, and it still does really
> well in pracftice in time)
>
Again, "making it as expensive or not expensive as you want" is not
something unique about cfl-aa. With the right tweak one can also do it
with a traditional solver. The real interesting question here is how to
find out what locations are most likely to matter and worth making
expensive.
- Jia
None taken. I didn't say it is an easy problem. Pointer analysis on a
C-ish language is always hard no matter what approach one takes, let
alone tuning the precision on a per pointer basis.
>
> The other problem you mention is, IMHO, not actually as interesting.
> We already have traditional methods (value profiling, etc) of knowing
> which things matter. Static prediction of this has a long history of
> over promise and under delivery.
I agree that it is easier to get some quick hints with profiling, yet
like any other dynamic approaches profiling has its own drawbacks:
benchmark dependent, no soundness guarantees, etc. I believe it is still
not the time to conclude that we've already got a perfect solution on
this problem and declare death sentence to any attempts to seek a good
static prediction mechanism.
std::vector<int> V1 = { 1, 2, 3 };std::vector<int> V2 = { 4, 5, 6 };V1.pop_back(); // Mutates *thisauto length = V1.size();V2.pop_back(); // Mutates *thisauto zero = length - V1.size()
It changes all the time. Here’s a trivial example, assume no inlining and no AA other than the one in question:
std::vector<int> V1 = { 1, 2, 3 };std::vector<int> V2 = { 4, 5, 6 };
V1.pop_back(); // Mutates *this
auto length = V1.size();
V2.pop_back(); // Mutates *this
auto zero = length - V1.size()
In this case, the compiler should “obviously” be able to CSE length, allowing further simplification to substitute zero with 0.
However, with a context sensitive AA, both &V1 and &V2 end up aliasing the “this” pointer in std::vector::pop_back. As such, without context sensitivity, you would falsely assume that “V2.pop_back();” could modify “V1”. This is unfortunate, particularly for OO languages that frequently use static dispatch (like C++, Swift, and others).
That said, I have no idea what you’re referring to by "context-insensitive function summary”. If you’re talking about something context sensitive, then ya, it can handle this. :-)
For the example to work here the CSE pass itself needs to be flow-sensitive and context-sensitive. I don't think that's how most optimizations in LLVM work. If it is, then I agree with all you said. But if it isn't, there's no point in bumping up the context sensitivity just for the pointer analysis.
As Daniel mentioned earlier in this thread, the analysis analysis framework in LLVM doesn't provide any APIs for flow-sensitive queries as well as context-sensitive queries. This design choice almost eliminate any possibilities for a flow-sensitive or context-sensitive pointer analysis to be useful. Strangely, the set of APIs does support 1-CFA context-sensitive mod-ref queries (so I guess one could somehow reap some context-sensitive benefits out of them after all). To me that design incoherence looks confusing, but I'm pretty sure you know much better than me why it should work that way :)
- Jia
From: "Jia Chen via llvm-dev" <llvm...@lists.llvm.org>
To: "Chris Lattner" <clat...@apple.com>
Cc: "llvm-dev" <llvm...@lists.llvm.org>
Sent: Monday, March 28, 2016 10:10:12 AM
Subject: Re: [llvm-dev] Existing studies on the benefits of pointer analysis
On 03/28/2016 12:37 AM, Chris Lattner wrote:
For the example to work here the CSE pass itself needs to be flow-sensitive and context-sensitive. I don't think that's how most optimizations in LLVM work. If it is, then I agree with all you said. But if it isn't, there's no point in bumping up the context sensitivity just for the pointer analysis.It changes all the time. Here’s a trivial example, assume no inlining and no AA other than the one in question:
std::vector<int> V1 = { 1, 2, 3 };std::vector<int> V2 = { 4, 5, 6 };
V1.pop_back(); // Mutates *this
auto length = V1.size();
V2.pop_back(); // Mutates *this
auto zero = length - V1.size()
In this case, the compiler should “obviously” be able to CSE length, allowing further simplification to substitute zero with 0.
However, with a context sensitive AA, both &V1 and &V2 end up aliasing the “this” pointer in std::vector::pop_back. As such, without context sensitivity, you would falsely assume that “V2.pop_back();” could modify “V1”. This is unfortunate, particularly for OO languages that frequently use static dispatch (like C++, Swift, and others).
That said, I have no idea what you’re referring to by "context-insensitive function summary”. If you’re talking about something context sensitive, then ya, it can handle this. :-)
As Daniel mentioned earlier in this thread, the analysis analysis framework in LLVM doesn't provide any APIs for flow-sensitive queries as well as context-sensitive queries. This design choice almost eliminate any possibilities for a flow-sensitive or context-sensitive pointer analysis to be useful. Strangely, the set of APIs does support 1-CFA context-sensitive mod-ref queries (so I guess one could somehow reap some context-sensitive benefits out of them after all). To me that design incoherence looks confusing, but I'm pretty sure you know much better than me why it should work that way :)
- Jia
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
On 03/28/2016 12:37 AM, Chris Lattner wrote:
It changes all the time. Here’s a trivial example, assume no inlining and no AA other than the one in question:
std::vector<int> V1 = { 1, 2, 3 };std::vector<int> V2 = { 4, 5, 6 };
V1.pop_back(); // Mutates *this
auto length = V1.size();
V2.pop_back(); // Mutates *this
auto zero = length - V1.size()
Can you elaborate on what you mean by flow sensitive? We have a mod/ref query interface that can return answers specific to a particular instruction/call pair. The code above could easily live in a single basic block, and if we had function attribute deduction on the 'argmemonly' attribute, we could probably do this now.
-Hal
Can you elaborate on what you mean by flow sensitive? We have a mod/ref query interface that can return answers specific to a particular instruction/call pair. The code above could easily live in a single basic block, and if we had function attribute deduction on the 'argmemonly' attribute, we could probably do this now.
-Hal
What I meant is that the CSE needs to be aware of the execution order, i.e. the call to V1.pop_back() should not be in the middle of the two V1.size() for zero to be 0. If there exists more complicated control flows, CSE needs to be able to make the same kind of argument across basic blocks.
I didn't follow LLVM development very closely to be familiar with how LLVM handles CSE. If what I said above is exactly how it works today, then yes we could probably do this now.
But still, there is no APIs that answers "are p and q aliases before this instruction x?". The same can be done for mod-ref today (if I remembered correctly this isn't even the case before the AAResult class came into existence), but not for aliases.
auto length = V1.size();
V2.pop_back(); // Mutates *this
auto zero = length - V1.size()