Use the new addEscapingValue callback to update GlobalsModRef when GVN adds PHIs...
authorOwen Anderson <resistor@mac.com>
Mon, 3 Jan 2011 23:51:43 +0000 (23:51 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 3 Jan 2011 23:51:43 +0000 (23:51 +0000)
have GlobalsModRef handle this conservatively by simply removing the value from its maps.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122787 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/IPA/GlobalsModRef.cpp
lib/Analysis/NoAliasAnalysis.cpp
lib/Transforms/Scalar/GVN.cpp

index c18dc47406a8b1a0289fa0f232624e6e96a18c52..116aaf418ea0ebb6f8d4866bfcc80a3eb47723f8 100644 (file)
@@ -152,6 +152,7 @@ namespace {
 
     virtual void deleteValue(Value *V);
     virtual void copyValue(Value *From, Value *To);
+    virtual void addEscapingUse(Use &U);
 
     /// getAdjustedAnalysisPointer - This method is used when a pass implements
     /// an analysis interface through multiple inheritance.  If needed, it
@@ -596,3 +597,13 @@ void GlobalsModRef::deleteValue(Value *V) {
 void GlobalsModRef::copyValue(Value *From, Value *To) {
   AliasAnalysis::copyValue(From, To);
 }
+
+void GlobalsModRef::addEscapingUse(Use &U) {
+  // For the purposes of this analysis, it is conservatively correct to treat
+  // a newly escaping value equivalently to a deleted one.  We could perhaps
+  // be more precise by processing the new use and attempting to update our
+  // saved analysis results to accomodate it.
+  deleteValue(U);
+  
+  AliasAnalysis::addEscapingUse(U);
+}
index ab7a69241e9ae39e60fc15a9bcada04c9e5e0b33..101c2d5b0285aad238fef4290dc937e69bb0dad5 100644 (file)
@@ -65,6 +65,7 @@ namespace {
 
     virtual void deleteValue(Value *V) {}
     virtual void copyValue(Value *From, Value *To) {}
+    virtual void addEscapingUse(Use &U) {}
     
     /// getAdjustedAnalysisPointer - This method is used when a pass implements
     /// an analysis interface through multiple inheritance.  If needed, it
index bf46bd98c3defeab3e0019cdc57ec6efe53f07c2..f0e0f381425bbc2e9b28724f21c9cf1ca0a45a16 100644 (file)
@@ -1063,6 +1063,15 @@ static Value *ConstructSSAForLoadSet(LoadInst *LI,
   if (V->getType()->isPointerTy())
     for (unsigned i = 0, e = NewPHIs.size(); i != e; ++i)
       AA->copyValue(LI, NewPHIs[i]);
+    
+    // Now that we've copied information to the new PHIs, scan through
+    // them again and inform alias analysis that we've added potentially
+    // escaping uses to any values that are operands to these PHIs.
+    for (unsigned i = 0, e = NewPHIs.size(); i != e; ++i) {
+      PHINode *P = NewPHIs[i];
+      for (unsigned ii = 0, ee = P->getNumIncomingValues(); ii != ee; ++ii)
+        AA->addEscapingUse(P->getOperandUse(2*ii));
+    }
 
   return V;
 }
@@ -1957,8 +1966,16 @@ bool GVN::performPRE(Function &F) {
       insert_table(ValNo, Phi, CurrentBlock);
 
       CurInst->replaceAllUsesWith(Phi);
-      if (MD && Phi->getType()->isPointerTy())
-        MD->invalidateCachedPointerInfo(Phi);
+      if (Phi->getType()->isPointerTy()) {
+        // Because we have added a PHI-use of the pointer value, it has now
+        // "escaped" from alias analysis' perspective.  We need to inform
+        // AA of this.
+        for (unsigned ii = 0, ee = Phi->getNumIncomingValues(); ii != ee; ++ii)
+          VN.getAliasAnalysis()->addEscapingUse(Phi->getOperandUse(2*ii));
+        
+        if (MD)
+          MD->invalidateCachedPointerInfo(Phi);
+      }
       VN.erase(CurInst);
       erase_table(ValNo, CurInst, CurrentBlock);