[PATCH] Top-Down FunctionAttrs propagation for noalias, dereferenceable and nonnull inference

Nick Lewycky nlewycky at google.com
Mon Jul 21 20:21:30 PDT 2014

On 21 July 2014 19:46, Chandler Carruth <chandlerc at google.com> wrote:

> On Mon, Jul 21, 2014 at 7:31 PM, Nick Lewycky <nlewycky at google.com> wrote:
>> On 21 July 2014 17:08, hfinkel at anl.gov <hfinkel at anl.gov> wrote:
>>> Use isDereferenceablePointer (which checks things like argument's
>>> dereferenceable attribute) in addition to using isSafeToLoadUnconditionally
>>> (which is mostly useful for its local instruction scan). Also fixed up one
>>> of the test cases.
>> The iteration order of the functions within an SCC is non-deterministic
>> and may result in different attributes being added depending on pointer
>> comparison. Consider the case of two leaf functions sharing the same
>> parent, then add call edges between those two "leaf" functions. The df
>> iteration may visit either of those two first, and if one of them depends
>> on the attributes on the other, but the other does not, then you have an
>> order dependence.
> Would iterating to fix-point within an SCC be a reasonable solution?

It would be correct but wouldn't necessarily fit in O(n^2) time.

There is an efficient fix, it's just time consuming to implement. For a
per-function attribute, look at the (function call graph) SCC and determine
their attributes as a group, by checking whether any of the functions would
fail to have the attributes even if all the others did have the property.
If they all would have the attribute when the others do, mark them all as
having it. Otherwise, the only way each of them has the attribute is if you
could prove it to have the attribute you're looking for even when the other
functions in the SCC do not.

You can do this with a local scan of each function up front, breaking them
down into a) clearly gets attribute regardless of attributes on other
in-SCC functions b) clearly does not get attribute regardless of attributes
on other functions c) could get the attribute if the other in-SCC functions
do too. You can apply the attribute to anything in category a) immediately,
then everything in category c) gets the attribute only if nothing fell into
category b.

The dereferencable attribute is not a per-function property, it's a
per-argument property, so to handle this you'd need to build up an SCC
graph of the arguments. Note that you end up with a forest while
scc_iterator requires a connected graph, so in my implementation I add a
"synthetic root node", but after that point the rest of the reasoning is
the same. I added this to FunctionAttrs.cpp in r147327, if it helps to see
an implementation:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140721/02b82761/attachment.html>

More information about the llvm-commits mailing list