Attribute to mark that function only access memory through it's arguments

Hi,

Currently in AliasAnalysis we can model ModRef behaviour for functions which
only access memory through their pointer arguments. However we can't
express this propery as a function attribute.

For example, for intrinsics we can specify ReadWriteArgMem or ReadArgMem
attributes in tablegen definitions. But due to the lack of the related function
attributes on the llvm ir level, this intrinsics would be modelled as if they
were clobbering arbitrary memory.

It feels very naturall to add new function attribute which can cover such cases.

I have a patch (http://reviews.llvm.org/D10398) in which I added this
attribute. Currently there is some discussion on how to name it and how it should
behave when defined together with other fucntion attributes.

I wanted to get some feedback on this. Is this attribute required at all? Maybe
there is already a way of expressing such things?

Thanks,
Igor

Hi,

Currently in AliasAnalysis we can model ModRef behaviour for functions
which
only access memory through their pointer arguments. However we can't
express this propery as a function attribute.

For example, for intrinsics we can specify ReadWriteArgMem or ReadArgMem
attributes in tablegen definitions. But due to the lack of the related
function
attributes on the llvm ir level, this intrinsics would be modelled as if
they
were clobbering arbitrary memory.

It feels very naturall to add new function attribute which can cover such
cases.

I have a patch (⚙ D10398 Add read_write_arg_mem attribute) in which I added this
attribute. Currently there is some discussion on how to name it and how it
should
behave when defined together with other fucntion attributes.

What does it mean? Can it only touch memory that is directly referred to by
an argument? Or if that argument points to another pointer, can we follow
it?

I wanted to get some feedback on this. Is this attribute required at all?

Maybe
there is already a way of expressing such things?

The other way today is a custom AA pass. That can either use deduction, or
special knowledge about named functions in your runtime.

— Igor

I just want to point out that the notion Igor is introducing as an attribute is not a new one. It’s a prexisting notion which is already implemented within LLVM today; it’s simply been restricted to intrinsics. Here’s the definition from Intrinsics.td: // IntrReadWriteArgMem - This intrinsic reads and writes only from memory that // one of its arguments points to, but may access an unspecified amount. The // reads and writes may be volatile, but except for this it has no other side // effects. def IntrReadWriteArgMem : IntrinsicProperty; I did point out in the review that I think the notion of ReadsArgMem is redundant given the existing notions of ReadWriteArgMem and ReadOnly, but that’s somewhat orthogonal. It’s true of the existing implementation, not just Igor’s patch. It may be worth settling on this to clarify naming (i.e. are we ever going to need an attribute like reads_arg_mem? Or can we be more generic and use accesses_arg_mem + readonly for the same purpose?), but I don’t think that really changes the semantics in major ways. Philip

I haven’t heard any objection to the proposed attribute. Given that, I think we can go ahead and move forward.

Igor - Can you update the patch to use the name argmemonly (analogous to readonly, readnone)? As discussed, we want to factor out the read/write part and use the existing attributes. Make sure you update the docs to clarify the answer to Nick’s question regarding following pointers.

Once that’s done, I’ll take a close look and probably LGTM. We will need to find someone to review the bitcode/IR serialization though since I’m not familiar with those pieces.

After this goes in, a good cleanup would be to remove the special casing for intrinsics and have the td files drive the addition of the now standardized attributes. This would be both a good cleanup and ensure test coverage of the newly introduced attribute. As such, I’d like you (Igor) to commit to doing this after the first patch lands.

Philip

After this goes in, a good cleanup would be to remove the special casing for intrinsics and have the td files drive the addition of the now standardized attributes. This would be both a good cleanup and ensure test coverage of the newly introduced attribute. As such, I’d like you (Igor) to commit to doing this after the first patch lands.

Sure, I’ll do the follow up cleanups as soon as initial change lands.

— Igor