Hi there,
I am trying to understand how AliasAnalysis works out in LLVM. I used
the following simple test-case (test4.c):
--
void test()
{
int *jj, *kk;
int aa = 100;
jj = &aa;
*jj = 300;
}
int main()
{
test();
return 0;
}
--
Then I did "llvm-gcc -emit-llvm -c -o test4.bc test4.c" to get bc. I
tried the following 2 ways to get what I expect to get as
"alias-sets":
1. opt -aa-eval -print-all-alias-modref-info test4.bc
Function: test: 4 pointers, 0 call sites
NoAlias: i32* %aa, i32** %kk
NoAlias: i32* %aa, i32** %jj
NoAlias: i32** %jj, i32** %kk
MayAlias: i32* %0, i32* %aa
MayAlias: i32* %0, i32** %kk
MayAlias: i32* %0, i32** %jj
Function: main: 2 pointers, 1 call sites
NoAlias: i32* %0, i32* %retval
NoModRef: Ptr: i32* %retval <-> call void @test() nounwind
NoModRef: Ptr: i32* %0 <-> call void @test() nounwind
This way at least I could see " aa <- (kk, jj)" results from
mayalias.
2. opt -anders-aa -aa-eval -print-all-alias-modref-info test4.bc
Function: test: 4 pointers, 0 call sites
NoAlias: i32* %aa, i32** %kk
NoAlias: i32* %aa, i32** %jj
NoAlias: i32** %jj, i32** %kk
MayAlias: i32* %0, i32* %aa
NoAlias: i32* %0, i32** %kk
NoAlias: i32* %0, i32** %jj
Function: main: 2 pointers, 1 call sites
NoAlias: i32* %0, i32* %retval
NoModRef: Ptr: i32* %retval <-> call void @test() nounwind
NoModRef: Ptr: i32* %0 <-> call void @test() nounwind
I actullay would expect the more accurate results from applying
anders-aa, but I could not interpret what has been returned - at least
I should see something like jj->aa, right?
Maybe I missed something out, could someone on the mailing list share
some thoughts?
Thanks a lot!
Weihua
On Thu, May 14, 2009 at 2:19 PM, Weihua Sheng <weihua.sheng at gmail.com> wrote:> I actullay would expect the more accurate results from applying > anders-aa, but I could not interpret what has been returned - at least > I should see something like jj->aa, right?I'm not quite following... jj and aa don't alias; both versions show that. The results returned for anders-aa are completely precise except that it doesn't know that "%0" and "%aa" must point to exactly the same object. -Eli
Hi Eli, thanks for the answers helping out.
I tried to understand further - got another example:
void test()
{
int *jj, *kk;
int aa = 100;
jj = &aa;
*jj = 300;
kk = jj;
*kk = 400;
}
int main()
{
test();
return 0;
}
bc looks like the following (only test() part)
define void @test() nounwind {
entry:
%aa = alloca i32 ; <i32*> [#uses=2]
%kk = alloca i32* ; <i32**> [#uses=2]
%jj = alloca i32* ; <i32**> [#uses=3]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
store i32 100, i32* %aa, align 4
store i32* %aa, i32** %jj, align 8
%0 = load i32** %jj, align 8 ; <i32*> [#uses=1]
store i32 300, i32* %0, align 4
%1 = load i32** %jj, align 8 ; <i32*> [#uses=1]
store i32* %1, i32** %kk, align 8
%2 = load i32** %kk, align 8 ; <i32*> [#uses=1]
store i32 400, i32* %2, align 4
br label %return
return: ; preds = %entry
ret void
}
the andersens-aa gives out the following results:
Function: test: 6 pointers, 0 call sites
NoAlias: i32* %aa, i32** %kk
NoAlias: i32* %aa, i32** %jj
NoAlias: i32** %jj, i32** %kk
MayAlias: i32* %0, i32* %aa
NoAlias: i32* %0, i32** %kk
NoAlias: i32* %0, i32** %jj
MayAlias: i32* %1, i32* %aa
NoAlias: i32* %1, i32** %kk
NoAlias: i32* %1, i32** %jj
MayAlias: i32* %0, i32* %1
MayAlias: i32* %2, i32* %aa
NoAlias: i32* %2, i32** %kk
NoAlias: i32* %2, i32** %jj
MayAlias: i32* %0, i32* %2
MayAlias: i32* %1, i32* %2
which I interpret as (%0, %1, %aa, %2) as the alias set. Here comes
my beginner's question: will the AA give the result that kk and jj
alias (that's what I understand from C and possibly could see from
bc)? Thanks a lot again!
Weihua
On Fri, May 15, 2009 at 1:33 AM, Eli Friedman <eli.friedman at gmail.com>
wrote:> On Thu, May 14, 2009 at 2:19 PM, Weihua Sheng <weihua.sheng at
gmail.com> wrote:
>> I actullay would expect the more accurate results from applying
>> anders-aa, but I could not interpret what has been returned - at least
>> I should see something like jj->aa, right?
>
> I'm not quite following... jj and aa don't alias; both versions
show
> that. The results returned for anders-aa are completely precise
> except that it doesn't know that "%0" and "%aa"
must point to exactly
> the same object.
>
> -Eli
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>