[llvm-dev] Alias analysis only throwing mayAlias for something that seems should be identifiable as mustAlias

맹기완 via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 5 16:05:46 PST 2019

I have a global 2-D array ARRAY[N][M] and I am accessing it inside the for
loop like this:

for (i...)
  for (j ...)
    ARRAY[i][j] ...

So nothing really weird is happening. If I look at the generated IR, it is
also fairly straight forward.

@ARRAY0 = dso_local global [32 x [32 x i32]] zeroinitializer, section
".slow_mem", align 32, !dbg !84
%45 = getelementptr inbounds [32 x [32 x i32]], [32 x [32 x i32]]* @ARRAY0,
i32 0, i32 %22, i32 7, !dbg !180
store volatile i32 %43, i32* %45, align 4, !dbg !181, !tbaa !148

As you can see, the GEPInst exactly knows it is the ARRAY0, and it knows
statically that it is accessing the 7th element.
However, when I try to call alias analysis in the LLVM pass, as in

AliasAnalysis *AA = ...
AA->alias(a, b)

where a is the ARRAY0 global variable and b is the GEPInst (%45), I only
get mayAlias.
When reading the basicaa description, it seems like it should know that the
two is must alias. What am I missing?

I did not know how I should post code in the thread, so I apologize for the
messy format.
Thank you,
Best Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191105/7da47957/attachment-0001.html>

More information about the llvm-dev mailing list