Joerg Sonnenberger
2012-Dec-12 16:38 UTC
[LLVMdev] [cfe-dev] no-alias generated as result of restrict function arguments
On Tue, Dec 11, 2012 at 03:17:43AM -0800, Chandler Carruth wrote:> As Joerg pointed out in IRC, 'y' is an lvalue, but we do not use it to > access the object it designates, we only use it to compute the address, and > thus restrict should have no bearing on it. That would in turn make Clang's > optimization incorrect and also seems likely to make 'noalias' essentially > useless for modeling restrict. =/Looking a bit deeper, the issue is ultimately that isIdentifiedObject is true if NoAlias is specified for the argument. There is a comment at the beginning of AliasAnalysis.h that NoAlias doesn't imply inequal pointers. One of the uses in BasicAliasAnalysis.cpp seems also questionable ("Constant pointers can't alias with non-const isIdentifiedObject objects") in this light. What does constant pointer in this context mean? Is that assumption violated if I explicitly cast away const and pass the result to a function with NoAlias argument? I think the required changes for correctness of C restrict would be: Two identified objects do not alias, if they are both NoAlias arguments or both are not NoAlias arguments. If one of the identified objects is a NoAlias argument and the context in question considers the referenced object, they don't alias. For the purpose of pointer comparision, they are may be equal. Joerg
Dan Gohman
2012-Dec-12 19:01 UTC
[LLVMdev] [cfe-dev] no-alias generated as result of restrict function arguments
On Wed, Dec 12, 2012 at 8:38 AM, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:> On Tue, Dec 11, 2012 at 03:17:43AM -0800, Chandler Carruth wrote: >> As Joerg pointed out in IRC, 'y' is an lvalue, but we do not use it to >> access the object it designates, we only use it to compute the address, and >> thus restrict should have no bearing on it. That would in turn make Clang's >> optimization incorrect and also seems likely to make 'noalias' essentially >> useless for modeling restrict. =/ > > Looking a bit deeper, the issue is ultimately that isIdentifiedObject is > true if NoAlias is specified for the argument. There is a comment at the > beginning of AliasAnalysis.h that NoAlias doesn't imply inequal > pointers. > > One of the uses in BasicAliasAnalysis.cpp seems also questionable > ("Constant pointers can't alias with non-const isIdentifiedObject objects") > in this light. What does constant pointer in this context mean?It means the pointer value itself satisfies isa<Constant>.> Is that > assumption violated if I explicitly cast away const and pass the result > to a function with NoAlias argument?Not immediately, no. It means that you can't access the constant pointer's pointee directly within the noalias argument's scope. Access to that object must go through the noalias argument. Restrict on a pointer loosely means "All accesses to my pointee(s) in my scope must go through me". It doesn't mean "I'm the only pointer value in the program which points to my pointee(s)"; in fact, that would be an unusable definition. Consequently, pointers that aren't used to access objects aren't constrained by restrict rules. Dan
Joerg Sonnenberger
2012-Dec-12 21:26 UTC
[LLVMdev] [cfe-dev] no-alias generated as result of restrict function arguments
On Wed, Dec 12, 2012 at 11:01:01AM -0800, Dan Gohman wrote:> > Is that > > assumption violated if I explicitly cast away const and pass the result > > to a function with NoAlias argument? > > Not immediately, no. It means that you can't access the constant > pointer's pointee directly within the noalias argument's scope. Access > to that object must go through the noalias argument. > > Restrict on a pointer loosely means "All accesses to my pointee(s) in > my scope must go through me". It doesn't mean "I'm the only pointer > value in the program which points to my pointee(s)"; in fact, that > would be an unusable definition. Consequently, pointers that aren't > used to access objects aren't constrained by restrict rules.The original issue is that clang maps restrict on function arguments to NoAlias and that makes compares against the address of global variables false. Minimal test case: @y = external global i32 define zeroext i1 @t(i32* noalias %x) nounwind uwtable readnone { entry: %cmp = icmp eq i32* %x, @y ret i1 %cmp } Joerg
Seemingly Similar Threads
- [LLVMdev] [cfe-dev] no-alias generated as result of restrict function arguments
- [LLVMdev] [cfe-dev] no-alias generated as result of restrict function arguments
- [LLVMdev] [cfe-dev] no-alias generated as result of restrict function arguments
- Signed or unsigned EQ/NEQ
- [LLVMdev] How to use the return value of a CallInst