[llvm-commits] [llvm] r72403 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp test/Transforms/GVN/load-constant-mem.ll

Chris Lattner sabre at nondot.org
Mon May 25 14:28:56 PDT 2009


Author: lattner
Date: Mon May 25 16:28:56 2009
New Revision: 72403

URL: http://llvm.org/viewvc/llvm-project?rev=72403&view=rev
Log:
make memdep use the getModRefInfo method for stores instead of the
low-level alias() method, allowing it to reason more aggressively
about pointers into constant memory.  PR4189

Added:
    llvm/trunk/test/Transforms/GVN/load-constant-mem.ll
Modified:
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=72403&r1=72402&r2=72403&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Mon May 25 16:28:56 2009
@@ -202,9 +202,17 @@
     }
     
     if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
+      // If alias analysis can tell that this store is guaranteed to not modify
+      // the query pointer, ignore it.  Use getModRefInfo to handle cases where
+      // the query pointer points to constant memory etc.
+      if (AA->getModRefInfo(SI, MemPtr, MemSize) == AliasAnalysis::NoModRef)
+        continue;
+
+      // Ok, this store might clobber the query pointer.  Check to see if it is
+      // a must alias: in this case, we want to return this as a def.
       Value *Pointer = SI->getPointerOperand();
       uint64_t PointerSize = TD->getTypeStoreSize(SI->getOperand(0)->getType());
-
+      
       // If we found a pointer, check if it could be the same as our pointer.
       AliasAnalysis::AliasResult R =
         AA->alias(Pointer, PointerSize, MemPtr, MemSize);

Added: llvm/trunk/test/Transforms/GVN/load-constant-mem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/load-constant-mem.ll?rev=72403&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/GVN/load-constant-mem.ll (added)
+++ llvm/trunk/test/Transforms/GVN/load-constant-mem.ll Mon May 25 16:28:56 2009
@@ -0,0 +1,13 @@
+; RUN: llvm-as < %s | opt -gvn -instcombine | llvm-dis | grep {ret i32 0}
+; PR4189
+ at G = external constant [4 x i32]
+
+define i32 @test(i8* %p, i32 %i) nounwind {
+entry:
+	%P = getelementptr [4 x i32]* @G, i32 0, i32 %i
+	%A = load i32* %P
+	store i8 4, i8* %p
+	%B = load i32* %P
+	%C = sub i32 %A, %B
+	ret i32 %C
+}





More information about the llvm-commits mailing list