[LLVMdev] Limitations of Alias Analysis?

Török Edwin
Mon, 29 Jun 2009 08:48:52 -0000

On 2009-06-29 11:16, Wenzhi Tao wrote:
> Hi, all
>
>   According to the document "LLVM Alias Analysis Infrastructure",
I
> evaluated the AA performance by using the paramenters '-basicaa -ds-aa
> -anders-aa'. The source code 'test.c' is listed as follow:
> [...]
> The whole process:
>
> llvm-gcc -emit-llvm -O0 -c test.c -o test.bc
>
> opt test.bc -load libLLVMDataStructure.so -basic-aa -ds-aa -anders-aa
> -aa-eval -print-all-alias-modref-info
>

Try this:
opt -mem2reg -functionattrs -basic-aa -aa-eval
-print-all-alias-modref-info test.bc

It shows:
  NoAlias:      %struct.Location* %0, %struct.Location* %1

> %1 and %2 are considered as MayAlias results that while using
> llvm::MemoryDependenceAnalysis, %2 is dependent on %1(clobber). But in
> fact it's not.
>
> Maybe a flow-sensitive, context-sensitive alias analysis algorithm is
> needed to generate more precise result? Correct me, if I'm wrong. Thank
> you.
>

Running the functionattrs pass should be enough to add the 'noalias'
marker on getNewLocation(), and then even basic-aa can see that loc1 and
loc2 are NoAlias.
You also need to run -mem2reg, because otherwise -functionattrs doesn't
see that the return value is coming from a malloc (which already has
noalias attribute).

Best regards,
--Edwin