[LLVMdev] [cfe-dev] no-alias generated as result of restrict function arguments

Dan Gohman dan433584 at gmail.com
Wed Dec 12 13:59:55 PST 2012


On Wed, Dec 12, 2012 at 1:26 PM, Joerg Sonnenberger
<joerg at britannica.bec.de> wrote:
> 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
> }

The bug here isn't in clang's use of noalias or in BasicAliasAnalysis'
implementation of noalias; it's in the code that's optimizing the
icmp.

Dan



More information about the llvm-dev mailing list