[llvm-commits] [llvm] r85380 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp test/Transforms/GVN/invariant-simple.ll

Owen Anderson resistor at mac.com
Tue Oct 27 23:30:53 PDT 2009


Author: resistor
Date: Wed Oct 28 01:30:52 2009
New Revision: 85380

URL: http://llvm.org/viewvc/llvm-project?rev=85380&view=rev
Log:
Be more careful about invariance reasoning on "store" queries.  Stores still need
to depend on Ref and ModRef calls within the invariant region.

Modified:
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
    llvm/trunk/test/Transforms/GVN/invariant-simple.ll

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

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Wed Oct 28 01:30:52 2009
@@ -230,12 +230,11 @@
       return MemDepResult::getDef(Inst);
     }
     
-    // If we're querying on a store and we're in an invariant region, we're done
-    // at this point. The only things that stores depend on that could exist in
-    // an invariant region are loads, which we've already checked.
-    if (invariantTag) continue;
-    
     if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
+      // There can't be stores to the value we care about inside an 
+      // invariant region.
+      if (invariantTag) continue;
+      
       // 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.
@@ -280,12 +279,16 @@
     case AliasAnalysis::NoModRef:
       // If the call has no effect on the queried pointer, just ignore it.
       continue;
+    case AliasAnalysis::Mod:
+      // If we're in an invariant region, we can ignore calls that ONLY
+      // modify the pointer.
+      if (invariantTag) continue;
+      return MemDepResult::getClobber(Inst);
     case AliasAnalysis::Ref:
       // If the call is known to never store to the pointer, and if this is a
       // load query, we can safely ignore it (scan past it).
       if (isLoad)
         continue;
-      // FALL THROUGH.
     default:
       // Otherwise, there is a potential dependence.  Return a clobber.
       return MemDepResult::getClobber(Inst);

Modified: llvm/trunk/test/Transforms/GVN/invariant-simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/invariant-simple.ll?rev=85380&r1=85379&r2=85380&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/GVN/invariant-simple.ll (original)
+++ llvm/trunk/test/Transforms/GVN/invariant-simple.ll Wed Oct 28 01:30:52 2009
@@ -16,6 +16,21 @@
   ret i8 %2
 }
 
+define i8 @test2(i8* %P) nounwind {
+; CHECK: @test2
+; CHECK: store i8 1
+; CHECK: store i8 2
+; CHECK: ret i8 0
+entry:
+  store i8 1, i8* %P
+  %0 = call {}* @llvm.invariant.start(i64 32, i8* %P)
+  %1 = tail call i32 @bar(i8* %P)
+  call void @llvm.invariant.end({}* %0, i64 32, i8* %P)
+  store i8 2, i8* %P
+  ret i8 0
+}
+
 declare i32 @foo(i8*) nounwind 
+declare i32 @bar(i8*) nounwind readonly
 declare {}* @llvm.invariant.start(i64 %S, i8* nocapture %P) readonly
 declare void @llvm.invariant.end({}* %S, i64 %SS, i8* nocapture %P)
\ No newline at end of file





More information about the llvm-commits mailing list