Something must be wrong, more probable on my side. So the C source code is unchanged, I just did another experiment to first extract all the GEPs in the code, and call AliasAnalysis::alias on each pair of GEPs. Here is the code:
AliasAnalysis &AA = getAnalysis();
TargetData &TD = getAnalysis();
for (Module::iterator it = M.begin(); it != M.end(); it++){
Function &F = *it;
errs().write_escaped(F.getName()) << ‘\n’;
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
Instruction *Inst = &*I;
if ( GetElementPtrInst *gep = dyn_cast(Inst) )
geps.push_back(gep);
}
}
errs() << “List of GEPs:\n”;
for(std::list<GetElementPtrInst* >::iterator itGep1
= geps.begin(); itGep1 != geps.end(); itGep1++){
GetElementPtrInst *gep1 = *itGep1;
Type *t1 = ((PointerType )gep1->getType())->getElementType();
int64_t size1 = TD.getTypeAllocSize(t1);
std::list<GetElementPtrInst >::iterator itGep2 = itGep1;
for(; itGep2 != geps.end(); itGep2++){
GetElementPtrInst *gep2 = *itGep2;
gep1->dump();
errs() << “–>”;
gep2->dump();
Type *t2 = ((PointerType *)gep2->getType())->getElementType();
int64_t size2 = TD.getTypeAllocSize(t2);
AliasAnalysis::AliasResult aa = AA.alias(gep1, size1,
errs() << " alias: " << aa << “\n”;
}
}
Here is the result:
%9 = getelementptr inbounds i32* %8, i32 %7
→ %9 = getelementptr inbounds i32* %8, i32 %7
alias: 1
%9 = getelementptr inbounds i32* %8, i32 %7
→ %13 = getelementptr inbounds i32* %12, i32 %11
alias: 1
%9 = getelementptr inbounds i32* %8, i32 %7
→ %18 = getelementptr inbounds i32* %17, i32 %16
alias: 1
%9 = getelementptr inbounds i32* %8, i32 %7
→ %8 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 %7
alias: 1
%9 = getelementptr inbounds i32* %8, i32 %7
→ %13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
alias: 1
%9 = getelementptr inbounds i32* %8, i32 %7
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
alias: 1
%13 = getelementptr inbounds i32* %12, i32 %11
→ %13 = getelementptr inbounds i32* %12, i32 %11
alias: 1
%13 = getelementptr inbounds i32* %12, i32 %11
→ %18 = getelementptr inbounds i32* %17, i32 %16
alias: 1
%13 = getelementptr inbounds i32* %12, i32 %11
→ %8 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 %7
alias: 1
%13 = getelementptr inbounds i32* %12, i32 %11
→ %13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
alias: 1
%13 = getelementptr inbounds i32* %12, i32 %11
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
alias: 1
%18 = getelementptr inbounds i32* %17, i32 %16
→ %18 = getelementptr inbounds i32* %17, i32 %16
alias: 1
%18 = getelementptr inbounds i32* %17, i32 %16
→ %8 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 %7
alias: 1
%18 = getelementptr inbounds i32* %17, i32 %16
→ %13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
alias: 1
%18 = getelementptr inbounds i32* %17, i32 %16
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
alias: 1
%8 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 %7
→ %8 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 %7
alias: 1
%8 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 %7
→ %13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
alias: 1
%8 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 %7
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
alias: 1
%13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
→ %13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
alias: 1
%13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
alias: 1
%14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
alias: 1
How can be each pair MayAlias? That’s simply wrong! For example:
%13 = getelementptr inbounds [10 x i32]* %a, i32 0, i32 0
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
Must not alias,
while
%14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
→ %14 = getelementptr inbounds [10 x i32]* %b, i32 0, i32 0
Must alias.
Can someone help identifying where is wrong with my code?
Thanks!
Welson