[llvm-commits] [llvm] r60167 - /llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp

Chris Lattner sabre at nondot.org
Thu Nov 27 00:18:21 PST 2008


Author: lattner
Date: Thu Nov 27 02:18:12 2008
New Revision: 60167

URL: http://llvm.org/viewvc/llvm-project?rev=60167&view=rev
Log:
enhance FindAvailableLoadedValue to make use of AliasAnalysis
if it has it.

Modified:
    llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp

Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=60167&r1=60166&r2=60167&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Thu Nov 27 02:18:12 2008
@@ -20,6 +20,7 @@
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/Dominators.h"
+#include "llvm/Target/TargetData.h"
 #include <algorithm>
 using namespace llvm;
 
@@ -390,6 +391,13 @@
                                       unsigned MaxInstsToScan,
                                       AliasAnalysis *AA) {
   if (MaxInstsToScan == 0) MaxInstsToScan = ~0U;
+
+  // If we're using alias analysis to disambiguate get the size of *Ptr.
+  unsigned AccessSize = 0;
+  if (AA) {
+    const Type *AccessTy = cast<PointerType>(Ptr->getType())->getElementType();
+    AccessSize = AA->getTargetData().getTypeStoreSizeInBits(AccessTy);
+  }
   
   while (ScanFrom != ScanBB->begin()) {
     // Don't scan huge blocks.
@@ -415,14 +423,25 @@
            isa<GlobalVariable>(SI->getOperand(1))))
         continue;
       
+      // If we have alias analysis and it says the store won't modify the loaded
+      // value, ignore the store.
+      if (AA &&
+          (AA->getModRefInfo(SI, Ptr, AccessSize) & AliasAnalysis::Mod) == 0)
+        continue;
+      
       // Otherwise the store that may or may not alias the pointer, bail out.
       ++ScanFrom;
       return 0;
     }
     
-    
     // If this is some other instruction that may clobber Ptr, bail out.
     if (Inst->mayWriteToMemory()) {
+      // If alias analysis claims that it really won't modify the load,
+      // ignore it.
+      if (AA &&
+          (AA->getModRefInfo(Inst, Ptr, AccessSize) & AliasAnalysis::Mod) == 0)
+        continue;
+      
       // May modify the pointer, bail out.
       ++ScanFrom;
       return 0;





More information about the llvm-commits mailing list