[LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything

Hans Wennborg hans at hanshq.net
Wed Nov 4 01:51:23 PST 2009


This is the first patch I've sent to this project. Please be gentle :)

LLVM fails to remove the dead load in the following code when running
$./llvm-as -o - test.ll | ./opt -O3 -o - | ./llvm-dis -o -


%t = type { i32 }
declare void @foo(i8*)

define void @f(%t* noalias nocapture %stuff ) {
     %p = getelementptr inbounds %t* %stuff, i32 0, i32 0
     %before = load i32* %p

     call void @foo(i8* null)

     %after = load i32* %p ; <--- This should be removed!
     %sum = add i32 %before, %after;

     store i32 %sum, i32* %p
     ret void
}


The reason is that it is unsure whether the null pointer which is passed 
in the call to @foo may alias with %t. Obviously, a null pointer doesn't 
alias with anything, because it's not legal to read or write through it 
(right?).

The attached patch adds this check to BasicAliasAnalysis, and makes the 
dead load go away in my test.

Does this seem reasonable, and is my patch doing it the right way?


/ Hans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.patch
Type: text/x-patch
Size: 766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091104/8298ee32/attachment.bin>


More information about the llvm-dev mailing list