[llvm-commits] [llvm] r86582 - in /llvm/trunk: lib/Analysis/BasicAliasAnalysis.cpp test/Transforms/GVN/null-aliases-nothing.ll
Dan Gohman
gohman at apple.com
Mon Nov 9 11:29:11 PST 2009
Author: djg
Date: Mon Nov 9 13:29:11 2009
New Revision: 86582
URL: http://llvm.org/viewvc/llvm-project?rev=86582&view=rev
Log:
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)
Added:
llvm/trunk/test/Transforms/GVN/null-aliases-nothing.ll
Modified:
llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=86582&r1=86581&r2=86582&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Mon Nov 9 13:29:11 2009
@@ -646,6 +646,15 @@
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))
Added: llvm/trunk/test/Transforms/GVN/null-aliases-nothing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/null-aliases-nothing.ll?rev=86582&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/null-aliases-nothing.ll (added)
+++ llvm/trunk/test/Transforms/GVN/null-aliases-nothing.ll Mon Nov 9 13:29:11 2009
@@ -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
+}
More information about the llvm-commits
mailing list