[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Dec 8 23:14:51 PST 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.291 -> 1.292
---
Log message:

Implement trivial sinking for load instructions.  This causes us to sink 567 loads in spec


---
Diffs of the changes:  (+11 -1)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.291 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.292
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.291	Wed Dec  8 17:43:58 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Dec  9 01:14:34 2004
@@ -4206,7 +4206,17 @@
   if (isa<AllocaInst>(I) && I->getParent() == &DestBlock->getParent()->front())
     return false;
 
-  if (isa<LoadInst>(I)) return false;
+  // We can only sink load instructions if there is nothing between the load and
+  // the end of block that could change the value.
+  if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
+    if (LI->isVolatile()) return false;  // Don't sink volatile loads.
+
+    for (BasicBlock::iterator Scan = LI, E = LI->getParent()->end();
+         Scan != E; ++Scan)
+      if (Scan->mayWriteToMemory())
+        return false;
+    std::cerr << "SUNK LOAD: " << *LI;
+  }
 
   BasicBlock::iterator InsertPos = DestBlock->begin();
   while (isa<PHINode>(InsertPos)) ++InsertPos;






More information about the llvm-commits mailing list