[llvm-dev] Question about Alias Analysis with restrict keyword

jingu@codeplay.com via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 19 02:33:57 PDT 2018

Hi Eli,

I appreciate your good comments. It is very helpful.

Thanks again,

JinGu Kang

On 18/06/18 23:17, Friedman, Eli wrote:
> On 6/18/2018 8:16 AM, jingu at codeplay.com wrote:
>> On BasicAAResult::aliasGEP()
>> 1297     // Check to see if these two pointers are related by the 
>> getelementptr
>> 1298     // instruction.  If one pointer is a GEP with a non-zero 
>> index of the other
>> 1299     // pointer, we know they cannot alias.
>> 1300
>> 1301     // If both accesses are unknown size, we can't do anything 
>> useful here.
>> 1302     if (V1Size == MemoryLocation::UnknownSize &&
>> 1303         V2Size == MemoryLocation::UnknownSize)
>> 1304       return MayAlias;
> The check for UnknownSize is here because it's impossible to 
> disambiguate the offsets of two pointers which both have unknown size, 
> so the rest of BasicAAResult::aliasGEP can't do anything useful.
>> 1305
>> 1306     AliasResult R = aliasCheck(UnderlyingV1, 
>> MemoryLocation::UnknownSize,
>> 1307                                AAMDNodes(), V2, 
>> MemoryLocation::UnknownSize,
>> 1308                                V2AAInfo, nullptr, UnderlyingV2);
>> On line 1306, we can see the V1Size and V2Size are set up with 
>> "MemoryLocation::UnknownSize" and it causes may-alias. On line 1302 
>> and 1033, there are checking code for 
>> "MemoryLocation::UnknownSize"... I am not sure whether it is bug or 
>> not... Can someone let me know why it passes 
>> "MemoryLocation::UnknownSize" please? If I missed something, please 
>> let me know.
> UnderlyingV1 is the base of the GEP.  So this is asking whether the 
> base of the GEP aliases V2.  It uses UnknownSize because the offset is 
> unknown; it can't tell which bytes are accessed, so it's using an 
> approximation instead.
> We could theoretically try to be a bit more clever here if the size is 
> known and the GEP offset is constant: we could instead pass 
> V1Size+GEP1BaseOffset.  Not sure that would have much effect in 
> practice, though.
> -Eli

Software Engineer, Compilers
Codeplay Software Ltd
Level C Argyle House, 3 Lady Lawson Street, Edinburgh, United Kingdom, EH3 9DR
Tel: +44 (0)131 466 0503
Website: http://www.codeplay.com
Twitter: https://twitter.com/codeplaysoft

This email and any attachments may contain confidential and /or privileged information and is for use by the addressee only. If you are not the intended recipient, please notify Codeplay Software Ltd immediately and delete the message from your computer. You may not copy or forward it, or use or disclose its contents to any other person. Any views or other information in this message which do not relate to our business are not authorized by Codeplay software Ltd, nor does this message form part of any contract unless so stated.
As internet communications are capable of data corruption Codeplay Software Ltd does not accept any responsibility for any changes made to this message after it was sent. Please note that Codeplay Software Ltd does not accept any liability or responsibility for viruses and it is your responsibility to scan any attachments.
Company registered in England and Wales, number: 04567874
Registered office: Regent House, 316 Beulah Hill, London, United Kingdom, SE19 3HF

More information about the llvm-dev mailing list