[LLVMdev] "Best" alias analysis algorithm

Vladimir Prus ghost at cs.msu.su
Mon Apr 25 05:09:42 PDT 2005


On Monday 25 April 2005 14:43, Vladimir Prus wrote:

> The 'i' variable is never modified in the program, however, all analyses
> except for -globalsmodref-aa report that the
>
>     	%tmp.3 = call int %_Z3bari( int %p )		; <int> [#uses=1]
>
> instruction can modify 'i'. I'm somewhat surprised, because it looks like
> -globalsmodref-aa is the simplest algorithm. So, why the order algorithms
> report possible modification?
>
> In fact, if I add
>
>    %j = external global int		;
>
> which is not used *anywhere*, most algorithms report that %j is modified by
> the call. Am I missing something, or -globalsmodref-aa is the only alias
> analysis that properly handles globals?

Things are actually worse. If I declare two global variables, and modify the 
called function so that it changes just one variable, then alias analysis 
(with --globalsmodref-aa) reports that the call instruction can write to both 
global variables.

The C++ program is at
http://zigzag.lvk.cs.msu.su/~ghost/localize/a.cpp

The LLVM bytecode is at
http://zigzag.lvk.cs.msu.su/~ghost/localize/a.ll

And the output from my code is 
http://zigzag.lvk.cs.msu.su/~ghost/localize/output.txt

The code itself is in
http://zigzag.lvk.cs.msu.su/~ghost/localize/code/

The GlobalsModRef::getModRefInfo has this logic:

    // If we are asking for mod/ref info of a direct call with a pointer to a
    // global we are tracking, return information if we have it.
    if (GlobalValue *GV = const_cast<GlobalValue*>(getUnderlyingObject(P)))
       if (GV->hasInternalLinkage())

So, no information is produced for external variables, the function calls 
Aliasanalysis::getModRefInfo, which sees that called function may write to 
memory, and returns true for all global variables.

Anything I can do about it? What I what is minimally accurate information 
about all global variables a function may modify. "Modifies them all" is 
clearly not even minimally accurate.

- Volodya




More information about the llvm-dev mailing list