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

Chris Lattner lattner at cs.uiuc.edu
Wed Dec 10 14:44:05 PST 2003


Changes in directory llvm/lib/Transforms/Scalar:

LICM.cpp updated: 1.47 -> 1.48

---
Log message:

Don't allow dead instructions to stop sinking early.


---
Diffs of the changes:  (+9 -10)

Index: llvm/lib/Transforms/Scalar/LICM.cpp
diff -u llvm/lib/Transforms/Scalar/LICM.cpp:1.47 llvm/lib/Transforms/Scalar/LICM.cpp:1.48
--- llvm/lib/Transforms/Scalar/LICM.cpp:1.47	Wed Dec 10 10:58:24 2003
+++ llvm/lib/Transforms/Scalar/LICM.cpp	Wed Dec 10 14:43:29 2003
@@ -366,7 +366,12 @@
   DEBUG(std::cerr << "LICM sinking instruction: " << I);
 
   const std::vector<BasicBlock*> &ExitBlocks = CurLoop->getExitBlocks();
-  
+  std::vector<Value*> Operands(I.op_begin(), I.op_end());
+
+  if (isa<LoadInst>(I)) ++NumMovedLoads;
+  ++NumSunk;
+  Changed = true;
+
   // The case where there is only a single exit node of this loop is common
   // enough that we handle it as a special (more efficient) case.  It is more
   // efficient to handle because there are no PHI nodes that need to be placed.
@@ -386,7 +391,6 @@
   } else if (ExitBlocks.size() == 0) {
     // The instruction is actually dead if there ARE NO exit blocks.
     I.getParent()->getInstList().erase(&I);
-    return;   // Don't count this as a sunk instruction, don't check operands.
   } else {
     // Otherwise, if we have multiple exits, use the PromoteMem2Reg function to
     // do all of the hard work of inserting PHI nodes as necessary.  We convert
@@ -469,17 +473,12 @@
     PromoteMemToReg(Allocas, *DT, *DF, AA->getTargetData());
   }
   
-  if (isa<LoadInst>(I)) ++NumMovedLoads;
-  ++NumSunk;
-  Changed = true;
-
   // Since we just sunk an instruction, check to see if any other instructions
   // used by this instruction are now sinkable.  If so, sink them too.
-  for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
-    if (Instruction *OpI = dyn_cast<Instruction>(I.getOperand(i)))
+  for (unsigned i = 0, e = Operands.size(); i != e; ++i)
+    if (Instruction *OpI = dyn_cast<Instruction>(Operands[i]))
       if (CurLoop->contains(OpI->getParent()) && canSinkOrHoistInst(*OpI) &&
-          isNotUsedInLoop(*OpI) &&
-          isSafeToExecuteUnconditionally(*OpI))
+          isNotUsedInLoop(*OpI) && isSafeToExecuteUnconditionally(*OpI))
         sink(*OpI);
 }
 





More information about the llvm-commits mailing list