Default-addressspace null pointers don't alias anything. This allows

GVN to be more aggressive. Patch by Hans Wennborg! (with a comment added by me)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86582 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2009-11-09 19:29:11 +00:00
parent 980d494ab6
commit f75ef668a7
2 changed files with 29 additions and 0 deletions

View File

@ -646,6 +646,15 @@ BasicAliasAnalysis::aliasCheck(const Value *V1, unsigned V1Size,
const Value *O1 = V1->getUnderlyingObject();
const Value *O2 = V2->getUnderlyingObject();
// Null values in the default address space don't point to any object, so they
// don't alias any other pointer.
if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(O1))
if (CPN->getType()->getAddressSpace() == 0)
return NoAlias;
if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(O2))
if (CPN->getType()->getAddressSpace() == 0)
return NoAlias;
if (O1 != O2) {
// If V1/V2 point to two different objects we know that we have no alias.
if (isIdentifiedObject(O1) && isIdentifiedObject(O2))

View File

@ -0,0 +1,20 @@
; RUN: opt %s -gvn -S | FileCheck %s
%t = type { i32 }
declare void @test1f(i8*)
define void @test1(%t* noalias %stuff ) {
%p = getelementptr inbounds %t* %stuff, i32 0, i32 0
%before = load i32* %p
call void @test1f(i8* null)
%after = load i32* %p ; <--- This should be a dead load
%sum = add i32 %before, %after;
store i32 %sum, i32* %p
ret void
; CHECK: load
; CHECK-NOT: load
; CHECK: ret void
}