[LLVMdev] "Best" alias analysis algorithm

Vladimir Prus ghost at cs.msu.su
Mon Apr 25 03:43:14 PDT 2005

I'm playing with alias analysis, using the following program:

    %i = external global int		; <int*> [#uses=2]
    implementation   ; Functions:
    int %_Z3bari(int %p) {
    	%tmp.0 = load int* %i		; <int> [#uses=1]
    	%tmp.1 = setgt int %tmp.0, 10		; <bool> [#uses=1]
    	br bool %tmp.1, label %then, label %UnifiedReturnBlock
    then:		; preds = %entry
    	%tmp.3 = add int %p, 2		; <int> [#uses=1]
    	ret int %tmp.3
    UnifiedReturnBlock:		; preds = %entry
    	ret int 0
    int %_Z3fooi(int %p) {
    	%tmp.0 = load int* %i		; <int> [#uses=1]
    	%tmp.1 = setgt int %tmp.0, 15		; <bool> [#uses=1]
    	br bool %tmp.1, label %UnifiedReturnBlock, label %else
    else:		; preds = %entry
    	%tmp.3 = call int %_Z3bari( int %p )		; <int> [#uses=1]
    	ret int %tmp.3
    UnifiedReturnBlock:		; preds = %entry
    	ret int %p
For each instruction, I call AliasAnalysis::getModRefInfo with the 'i' global 
variable. I tried different alias analyses -- the default one, --aa-eval, 
--anders-aa, -steens-aa and -globalsmodref-aa.

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?

- Volodya

More information about the llvm-dev mailing list