[LLVMdev] sample-code for alias-analysis
Nick Lewycky
nicholas at mxc.ca
Thu Mar 19 21:01:18 PDT 2009
RAAD B wrote:
>
> Hi,
>
> i need a sample-code, for which the llvm alias-analysis finds a
> *must-aliases*.
> I have tried codes like followings. In all cases, i see just
> *may-aliases* when i use "opt -aa-eval -print-all-alias-modref-info foo.bc":
Your examples are all .c files. What did your .ll look like? Here's the
problem:
$ llvm-g++ -O0 ex1.c -S -o - -emit-llvm
define void @_Z3foov() nounwind {
entry:
%r = alloca i32* ; <i32**> [#uses=1]
%i = alloca i32 ; <i32*> [#uses=2]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
store i32 2, i32* %i, align 4
store i32* %i, i32** %r, align 4
br label %return
return: ; preds = %entry
ret void
}
Obviously %r and %i don't alias: they're two separate heap allocations.
What you really want to do is run through some optimizations like
mem2reg and friends. But on that same example, it'll produce this:
$ llvm-g++ -O2 ex1.c -S -o - -emit-llvm
define void @_Z3foov() nounwind readnone {
entry:
ret void
}
The must-alias result is really hard to produce from a .c file because
it inherently means that one pointer is *exactly* equal to the other in
the sense that you could replace one with the other. One of them would
wind up being deleted.
You can cook up a .ll example easily enough, or I suppose you could
fiddle with .c examples piped through select optimizations to produce an
example that works for you.
Nick
> Regards
> Raad
>
>
> 1 ==========================================
> void foo() {
> int i = 2;
> int& r = i;
> }
>
> 2 ===========================================
> void foo(){
> int gi;
> int *gip1 = &gi;
> int *gip2 = &gi;
> }
>
> 3 ==========================================
> void foo (double * fa){
> int fi, fj;
> fi = 0;
> fj = 2;
> if (! fa)
> fj = fj + 4;
> fa[fi] = fa[fi + fj];
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list