[LLVMdev] A very basic doubt about LLVM Alias Analysis

Török Edwin edwintorok at gmail.com
Sun Feb 14 09:36:17 PST 2010


On 02/14/2010 06:39 PM, ambika wrote:
> Oh m sorry for that mistake as I had points to in mind.
> But still what about the following prog:
>
> int main()
> {
>         int *i,*j,k;
>         i=&k;
>         j=&k;
>         k=4;
>         printf("%d,%d,%d",*i,*j,k);
>         return 0;
> }
>   

Your example is too simple, i,j,k don't exist after running mem2reg.
And well, without running mem2reg i and j will be stack variables, so
you need to look for the value that is loaded from them.
That is the real pointer:
  AliasSet[0x0x1631400,3] may alias, Mod/Ref   Pointers: (i32* %k, 4),
(i32* %tmp, 4), (i32* %tmp2, 4)

Here %tmp is i (  %tmp = load i32** %i ), %tmp2 is j ( %tmp2 = load
i32** %j).

If you make it a bit more complicated:
int main(int argc, char **argv)
{
        int *i=0,*j=0,k;
        if (argc > 1) {
          i=&k;
        } else {
          j=&k;
        }
        k=4;
        printf("%d,%d,%d,%p,%p",*i,*j,k,i,j);
        return 0;
}

Then you get this:
  AliasSet[0x0xb8e6a0,3] may alias, Mod/Ref   Pointers: (i32* %k, 4),
(i32* %i.0, 4), (i32* %j.0, 4)



More information about the llvm-dev mailing list