Hi,
I am trying to get the alias info for the following code. The alias analysis returns “MayAlias” for arrays “A” and “B” in both the functions instead of “NoAlias”. What passes should I run in opt before the alias analysis pass to get the accurate result?
Example:
//Note: static and called by func() only.
static int sum(int *A, int *B) {
int i = 0, sum1 = 0;
for (i = 0; i < 100; ++i) {
sum1 += A[i] + B[i];
}
return sum1;
}
int func () {
int A[100], B[100];
int i = 0;
for (; i < 100; ++i) {
A[i] = B[i] = i;
}
return sum(A,B);
}
Arguments to opt**:** “****-mem2reg -basicaa -scev-aa -print-alias-sets”
Output:
Function: func
Alias Set Tracker: 2 alias sets for 2 pointer values.
AliasSet[0x2bc88b0, 2] may alias, Mod/Ref Pointers: (i32* %A.arrayidx, 4), (i32* %B.arrayidx2, 4)
1 Unknown instructions: i32 %call
AliasSet[0x2bc8490, 1] must alias, Mod forwarding to 0x2bc88b0
Function: sum
Alias Set Tracker: 1 alias sets for 2 pointer values.
AliasSet[0x2bcbb50, 2] may alias, Ref Pointers: (i32* %A.arrayidx, 4), (i32* %B.arrayidx2, 4)
Thanks,
Vinay
Hi Vinay,
The new -cfl-aa has an IPA that might catch this. Also, I'm working on a new pass to do top-down function parameter attribute propagation, which should catch this (http://reviews.llvm.org/D4609), but it is not quite ready yet.
-Hal
Hi Hal,
I could not get the better result from the new “cfl-aa” as well. But “cfl-aa” seems to be less accurate than “basicaa” for the following basic example! Am I missing something?
Example:
int func () {
int A[100], B[100];
int i = 0, sum1 =0;
for (; i < 100; ++i) {
A[i] = B[i] = i;
}
for (i = 0; i < 100; ++i) {
sum1 += A[i] + B[i];
}
return sum1;
}
Output of “opt -mem2reg -basicaa –print-alias-sets”:
Alias Set Tracker: 2 alias sets for 4 pointer values.
AliasSet[0x3b01890, 2] may alias, Mod/Ref Pointers: (i32* %A.arrayidx, 4), (i32* %A.arrayidx9, 4)
AliasSet[0x3b012a0, 2] may alias, Mod/Ref Pointers: (i32* %B.arrayidx2, 4), (i32* %B.arrayidx7, 4)
Output of “opt -mem2reg –cfl-aa –print-alias-sets” and “opt –mem2reg –basicaa –cfl-aa –print-alias-sets”:
Alias Set Tracker: 1 alias sets for 4 pointer values.
AliasSet[0x3046890, 4] may alias, Mod/Ref Pointers: (i32* %A.arrayidx, 4), (i32* %B.arrayidx2, 4), (i32* %B.arrayidx7, 4), (i32* %A.arrayidx9, 4)
Thanks,
Vinay
From: "Vinay Madhusudan" <Vinay.Madhusudan@amd.com>
To: "Hal Finkel" <hfinkel@anl.gov>
Cc: "LLVM Developers Mailing List (llvmdev@cs.uiuc.edu)" <llvmdev@cs.uiuc.edu>
Sent: Tuesday, September 30, 2014 1:06:56 AM
Subject: RE: [LLVMdev] Alias Analysis across functions
Hi Hal,
I could not get the better result from the new “cfl-aa” as well. But
"cfl-aa" seems to be less accurate than "basicaa" for the following
basic example! Am I missing something?
cfl-aa is intended to be used as a supplement to, not a replacement for, basicaa. Use -cfl-aa -basicaa (the order is significant; this will query basicaa first).
-Hal