LLVM Alias Analysis problem

Dear LLVM developers,

My name is Artem Vopilov, I am a student at TU Darmstadt. I am writing to you again to ask about Alias Analysis.

Now I attached IR code and C code of program I analyze with Alias Analysis.

Running commands "opt -analyze -aa-eval -print-all-alias-modref-info" and for printing sets of alias "opt -analyze -aa-eval -print-alias-sets" gives me the results, that in main function variables %a, %0, %2, %4 alias.

However I expected from Alias Analysis to indicate that pointers which point to same memory location alias, namely, %ptra and %ptrb.
I learnt from your last messages, that "A pointer is just a variable containing memory address, so pointer itself will never alias with other pointers, but the ‘pointee’ will alias with other memory addresses."

My goal is to find sets of pointers, that point to the same memory locations.
Am I right, that with Alias Analysis I cannot accomplish my aim? Is it possible to achieve it using LLVM?
Thank you.

I am looking forward to hearing from you!

Respectfully yours,
Artem Vopilov

test_IR.txt (1.53 KB)

text.c (432 Bytes)

Hi Artem,

1) Please do not CC all the llvm lists you can find. llvm-dev is the one
   for questions like this one, llvm-admin, mailman, bugs-admin, ... are
   not.

2) Please attach the _full_ LLVM-IR you used, the ".txt" file you
   attached is not complete and therefore not helpful. We can all
   open/read ".ll" files and so should you. As long as you pass the -S
   flag to opt (and clang in combination with -emit-llvm) you get human
   readable (=plain text) LLVM-IR as outpu.

3) You should probably run something like:
    clang -emit-llvm -S -O3 -mllvm -disable-llvm-optzns test.c -o test.ll
   to get your initial IR. Then you probably want to continue with
    opt -S -mem2reg -instcombine -simplifycfg test.ll -o test_clean.ll
   to clean up the IR a bit (especially to remove the stack locations
   introduced for variables and transform them into "proper SSA values".)
   Finally you run your analyzes as you did before
    opt -analyze -aa-eval -print-all-alias-modref-info test_clean.ll
   to get your results. If you need help understand the results, please
   let us know and provide enough information for us to comprehend your
   problem. You should also take a look at the test.ll and test_clean.ll
   and make sure you fully understand what the code representation
   means. As I noted in the other thread, your example is to simple,
   after the stack locations are promoted to registers, there is no
   "ptra/ptrb" that could alias anymore.

I hope this helps.

Cheers,
  Johannes

Dear Johannes,

Thank you for your response!
I will follow the steps you described!

Best regards,
Artem

Hi Artem,

  1. Please do not CC all the llvm lists you can find. llvm-dev is the one
    for questions like this one, llvm-admin, mailman, bugs-admin, … are
    not.

  2. Please attach the full LLVM-IR you used, the “.txt” file you
    attached is not complete and therefore not helpful. We can all
    open/read “.ll” files and so should you. As long as you pass the -S
    flag to opt (and clang in combination with -emit-llvm) you get human
    readable (=plain text) LLVM-IR as outpu.

According to the function group comments, the missing line seems to be:
attributes #0 = { nounwind uwtable }

@Артём: Hi,
One other thing llvm-dev will need to know is the version of LLVM you’re using. It looks like it isn’t a recent version since load instructions changed a while back. For example:
%0 = load i32* %a.addr, align 4
from your .txt is now:
%0 = load i32, i32* %a.addr, align 4
in recent LLVM-IR.

>
> Hi Artem,
>
> 1) Please do not CC all the llvm lists you can find. llvm-dev is the one
> for questions like this one, llvm-admin, mailman, bugs-admin, ... are
> not.
>
> 2) Please attach the _full_ LLVM-IR you used, the ".txt" file you
> attached is not complete and therefore not helpful. We can all
> open/read ".ll" files and so should you. As long as you pass the -S
> flag to opt (and clang in combination with -emit-llvm) you get human
> readable (=plain text) LLVM-IR as outpu.

According to the function group comments, the missing line seems to be:
  attributes #0 = { nounwind uwtable }

@Артём: Hi,
One other thing llvm-dev will need to know is the version of LLVM you're using. It looks like it isn't a recent version since load instructions changed a while back. For example:
  %0 = load i32* %a.addr, align 4
from your .txt is now:
  %0 = load i32, i32* %a.addr, align 4
in recent LLVM-IR.

Good catch!

The full IR (at least for custom builds) will also include the llvm and
clang version, another thing that is missing from the ".txt" :wink:

Dear LLVM Developers,

Thank you for your last messages!
Now I attached to this email code of the original program, _full_ LLVM-IR and clean LLVM-IR.

I executed "opt -analyze -aa-eval -print-all-alias-modref-info" and "opt -analyze -aa-eval -print-alias-sets" on both generated LLVM-IR.
So, I also attached the results of running this commands.

I would like to ask you again the same question.
My goal is to find sets of pointers, that point to the same memory locations.
Am I right, that with Alias Analysis I cannot accomplish my aim? Is it possible to achieve it using LLVM?
Thank you.

I am looking forward to hearing from you!

Respectfully yours,
Artem Vopilov

test5.c (457 Bytes)

test5.ll (4.29 KB)

test5_clean.ll (1.27 KB)

IR_alias_sets.txt (3.12 KB)

IR_all_alias_modref_info.txt (58.8 KB)

IR_clean_alias_sets.txt (1010 Bytes)

IR_clean_all_alias_modref_info.txt (591 Bytes)