[LLVMdev] Incorrect result in LLVM Alias Analysis

Adarsh HV adarsh.hv99 at gmail.com
Fri Apr 13 08:58:14 PDT 2012


It contains the bitcode file(without any optimization) of the below program,
void map(int *a)
 {
  *a=20;
}
int main(){
int *a=(int *)malloc(sizeof(int));
*a=15;
map(a);
return 0;
}
I want to check if the pointer operand of each store instruction aliases
with the function's arguments. I have used below code for this,
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
               AU.addRequiredTransitive<AliasAnalysis>();
		AU.addPreserved<AliasAnalysis>();
}
virtual bool runOnFunction(Function &F) {
		AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
                 for(Function::iterator i=F.begin();i!=F.end();++i){
			for(BasicBlock::iterator j=i->begin();j!=i->end();++j)
			{
				if(dyn_cast<StoreInst>(j))
                                   {
				             StoreInst *SI=dyn_cast<StoreInst>(j);
				             AliasAnalysis::Location LocA = AA.getLocation(SI);
				             for(Function::arg_iterator k=F.arg_begin();
k!=F.arg_end();++k)
                                               {
				                  Value *v=dyn_cast<Value>(k);
				                  AliasAnalysis::Location
loc=AliasAnalysis::Location(v);
				                  AliasAnalysis::AliasResult ar=AA.alias(LocA,loc);
                                                }
                                    }
                              }
                        }
But I get 'May Alias' result for the store instruction that assigns the
value of 'a' to 20 in the 'map' function.Is the result not supposed to be
'Must alias'? 

Duncan Sands wrote:
> 
> Hi Adarsh,
> 
>> I have used the follwing command,
>> opt -load LLVComMan.so -ComMan -memdep -tbaa -mem2reg maptest.ll   -S
>> What option other than -mem2reg should be included in this case to get
>> the
>> right results? Does the order in which I specify the optimizations to be
>> run
>> make a difference?
> 
> what is in maptest.ll?
> 
> Ciao, Duncan.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 

-- 
View this message in context: http://old.nabble.com/Incorrect-result-in-LLVM-Alias-Analysis-tp33642041p33682791.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.




More information about the llvm-dev mailing list