[PATCH] Alias analysis take advantage of "invariant.load" metadata

Shuxin Yang shuxin.llvm at gmail.com
Wed Mar 6 09:50:44 PST 2013


Hi, Arnold:

   Thank you so much for code review. Commit in r176562.

Thanks
Shuxin

On 3/5/13 5:11 PM, Arnold Schwaighofer wrote:
> The patch looks good to me. Maybe Dan or Nick have some comments?
>
>
> When you commit this patch please change the title from "Alias analysis" to "Memory Dependence Analysis" since that is where you are making use of the metadata.
>
>
> On Mar 5, 2013, at 4:50 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
>
>> Hi,
>>
>>     This defect is tracked by rdar://11311484.
>>
>>      The original motivating example is an ObjectiveC snippet. Unfortunately, I know nothing
>> about ObjectiveC. So, I use following C snippet to illustrate the motivation.  The loads
>> are manually annotated with "invariant.load" metadata. (Compile the snippet to get *.ll and
>> then then manually annotated the loads with "invariant.load" metadata)
>> With such annotation, GVN should be able to CSE away the redundant load.
>>
>> ------------------------
>> int foo(int *p, char *q) {
>>     *q = (char)*p;
>>     return *p + 1;
>> }
>> -------------------
>>
>>
>>     The change is made to class MemoryDependenceAnalysis.
> Seems like the appropriate place for this change to me.
>
>> We rely on the "invariant.load" metadata only when the analyzer fails to figure out if a load and
>> a store are definitely alias not definitely not alias,
>>
>>     I wish AliasAnalysis::alias() could take advantage of this metadata. However the interface of class
>> AliasAnalysis is defined in a way such that we are not able to tell the if the memory access in question
>> is load or store;
>> it seem the compiler is not supposed to blindly say 'no-alias' for pair of loads because,
>> as far as I can tell,  load-redundancy-elimination is triggered only when some optimizers see
>> some may-alias or must-alias loads.
> Yes, you would want AA to return MustAlias for two pointers in examples similar to the one above to be able to replace one by the other. Otherwise, you would have to rely on the equality of the pointer operand to the load.
>
> Best,
> Arnold




More information about the llvm-commits mailing list